简体   繁体   中英

three counts in one sql query

ID    FRUIT

1     Apple
2     Orange
3     Apple
4     Pear
5     Apple
6     Pear
7     Pear

I want to do a count of each fruit in a table. There are only three fruit, i only need totals.

I know how to do a SELECT COUNT(*) but not all three in one query

我想你想要这样的东西:

select fruit, count(id) from table group by fruit 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM