What is wrong in this query ?

Discussion in 'MySQL' started by deriklogov, Dec 6, 2009.

  1. #1
    QUERY:


    SELECT domain,distinct count (ip) as count FROM `stat` WHERE `time`='2009-12-6' group by `domain`


    I want to get list of records grouped by domains and in those records count number of records with unique ip address.
     
    deriklogov, Dec 6, 2009 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    put a separate after distinct and try again.

    If it is wrong too, write what king of error outputs.
     
    s_ruben, Dec 6, 2009 IP
  3. bluebenz

    bluebenz Well-Known Member

    Messages:
    876
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    138
    #3
    distinct is a field in your table?
    you can't use disctint as a field or table name.
    it's a reserve word..
     
    bluebenz, Dec 6, 2009 IP
  4. Kwaku

    Kwaku Well-Known Member

    Messages:
    1,217
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    140
    #4
    What are you trying to achieve; distinct count(ip) makes no sense.
     
    Kwaku, Dec 6, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Following might help..

    SELECT domain, COUNT (DISTINCT ip) AS DomainCount FROM `stat` WHERE `time`='2009-12-6' GROUP BY `domain`

    I hope time column's data type is date otherwise query will not yield anything.

    Let us know table structure and the report you wish with example and we will help you build query.
     
    mastermunj, Dec 6, 2009 IP
  6. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #6
    What records do you want to show? BTW Why are you using count() for the ip value? Why would you want to return the number of ips per domain?

    Maybe I don't understand and distinct and group by are always fun to play with lol. Hopefully you get it.
     
    clinton, Dec 7, 2009 IP