简体   繁体   中英

getting distinct column name and count when based on another table

i have the following query:

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

which return categories with duplicate rows. what i need is to get distinct categories, with the total count of accurences of that category, something like:

CATEGORY NAME | XXX ( where XXX is the count )

anyone can help?

Use this query instead :-

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 

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