wrong count in query

前端 未结 6 1046
故里飘歌
故里飘歌 2021-01-25 17:05

I have a table whose structure is as follows:

id  int
userid  int
status  enum (\'pending\',\'approved\')
dop     datetime

Data is as:

相关标签:
6条回答
  • 2021-01-25 17:53
    SELECT count( DISTINCT userid )
    FROM t1
    WHERE STATUS = 'pending'
    GROUP BY userid
    
    0 讨论(0)
  • 2021-01-25 17:54

    Try to add the userid in the select clause :

    SELECT userid, count( userid )
    FROM t1
    WHERE STATUS = 'pending'
    GROUP BY userid
    
    0 讨论(0)
  • 2021-01-25 17:56

    The group by statement is executed after the count. Use this instead:

    SELECT count( DISTINCT userid )
    FROM t1
    WHERE STATUS = 'pending'
    
    0 讨论(0)
  • 2021-01-25 18:03

    You sould use the COUNT(DISTINCT()) construction, it allow you to count the diferent values not NULL (docu)

    Try this sentence:

    SELECT count( DISTINCT( userid ) )
    FROM t1
    WHERE STATUS = 'pending'
    GROUP BY userid
    

    HTH!

    0 讨论(0)
  • 2021-01-25 18:06

    Do you want to count the number of user with status pending then?

    SELECT count(userid)
    FROM t1
    WHERE STATUS = 'pending'
    GROUP BY status, userid
    
    0 讨论(0)
  • 2021-01-25 18:06

    Maybe adding DISTINCT() on userid?

    0 讨论(0)
提交回复
热议问题