开发者

How to count all the enums in a SQL table

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜