开发者

How to count all the enums in a SQL table

开发者 https://www.devze.com 2022-12-12 01:58 出处:网络
Okay so I have a database field called moderated It is an ENUM with 3 values: approved denied unmoderated

Okay so I have a database field called moderated

It is an ENUM with 3 values:

approved
denied
unmoderated

How can I write a query that counts the amount of each, so I can generate this output:

Approved: 3
Denied: 10
Unmoder开发者_如何转开发ated: 23


If I understood your question correctly, you can write like this:

Select Moderated, Count(Moderated)  FROM YourTable
Group BY Moderated

If you want output in "approved: 3" format, you can add "Convert(Varchar(10), Moderated) + ':' + Convert(Varchar(10), Count(Moderated))" to you column list in you select statement.

0

精彩评论

暂无评论...
验证码 换一张
取 消