选择基于countries.havestate的机构ID计数。如果havestate=1,则count(institutions.instituteid)基于stateid,如if(institution.stateid='1'),然后count count(institutions.instituteid),否则count instituteid不带stateid,如下图所示。
SELECT countries.countryid,
Count(institutions.instituteid) AS instituteCount
FROM countries
RIGHT JOIN institutions
ON countries.countryid = institutions.countryid
WHERE countries.countryid = '32'
AND countries.status = '1'
暂无答案!
目前还没有任何答案,快来回答吧!