今天我发了一篇关于我在sql上遇到的问题的帖子,在那边的一些人的帮助下,我想出了我的查询必须如何。
现在我有一个不同的问题,我之前的查询结果:
select
count(case when Job = 'Garbageman' then 1 end) as GarbageCount,
count(case when Job = 'Delivery' then 1 end) as DeliveryCount
from Job
是:
GarbageCount: DelivryCount:
4 5
我想要实现的目标如下:
Job: Count:
Garbage 4
Delivery 5
我的表格如下:
User: Job:
Mark Garbageman
Dirk Garbageman
Henk Garbageman
Steven Garbageman
Mark Delivery
Dirk Delivery
Henk Delivery
Steven Delivery
Stevens Delivery
任何人都知道我的sql查询应该是什么样的?
答案 0 :(得分:0)
Group by
就是您正在寻找的所有内容:
select job, count(*)
from yourtable
group by job