COUNT DISTINCT with CONDITIONS

前端 未结 5 665
南方客
南方客 2020-12-07 09:10

I want to count the number of distinct items in a column subject to a certain condition, for example if the table is like this:

tag | entryID
----+---------
         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 09:18

    This may work:

    SELECT Count(tag) AS 'Tag Count'
    FROM Table
    GROUP BY tag
    

    and

    SELECT Count(tag) AS 'Negative Tag Count'
    FROM Table
    WHERE entryID > 0
    GROUP BY tag
    

提交回复
热议问题