繁体   English   中英

基于另一个表时获得不同的列名和计数

[英]getting distinct column name and count when based on another table

我有以下查询:

select cc.category from companies c
left join categories cc on c.category_id = cc.category_id
where company_title like '%gge%';

返回具有重复行的类别。 我需要的是获取不同的类别,并带有该类别的准确总数,例如:

类别名称| XXX(其中XXX是计数)

有人可以帮忙吗?

使用此查询代替:

select distinct cc.category,
count(cc.category) as totalCategoryCount
 from companies c
left join categories cc on c.category_id = cc.category_id
where company_title like '%gge%'
group by cc.category 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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