我有两个表service_category和category_mapping。我想显示特定类别中列出的公司类别和数量
Table service_category:
id cattegory mappingid
1 Construction cc
2 InteriorDesign idn
3 TechnicalWork tw
4 MarineConstruction mc
Table category_mapping:
id companyid cc idn tw mc
1 4 Y Y N N
2 5 N Y N Y
3 6 N N N Y
4 7 Y N N N
类似这样的事情
SELECT sc.*,(select count(*) from category_mapping where `XYZ`='Y' ) as companycount FROM service_category as sc
任何人都可以帮助我吗?
答案 0 :(得分:0)
如果有更多类别,这将仅对提及的类别有用..
select id, cattegory ,mappingid ,(select count(*) from category_mapping where cc='Y') as count
from
service_category
where mappingid='CC'
union
select id, cattegory ,mappingid ,(select count(*) from category_mapping where idn='Y') as count
from
service_category
where mappingid='idn'