[英]SQL count each distinct value in column and add name from another table where the ID matches
[英]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.