我有一个名为Field的表:
Category | Industry | Company
Research Science Biolite
Retail Healthcare The Vitamin Shop
Crafts Stationery Art Centre
Research Science GeneSys
Retail Healthcare Live Healthy
Crafts Stationery Typewrite Pens我希望能够找到每个行业的公司总数,然后按类别排序结果,然后行业。(例如,对于Science将有2家公司,对于Healthcare将有2家公司,对于文具也将有2家公司)。输出应如下所示(无序):
Category | Industry | Number
Research Science 2
Retail Healthcare 2
Crafts Stationery 2我有以下疑问:
select t1.Category, t1.Industry, t2.Number from Field t1
inner join (
select Industry, count(*) as Number from Field
group by Industry
) t2
on t1.Industry = t2.Industry;但是,在结果表中的行业列中,显示了重复的行业(例如,科学显示了两次)。如何让行业栏只显示每个行业一次?
发布于 2019-03-27 10:57:31
按类别和行业分组:
select Category,Industry, count(*) as 'Number'
from Field
group by Category,Industryhttps://stackoverflow.com/questions/55369066
复制相似问题