在mysql中基于条件显示计数值

ljsrvy3e  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(198)

选择基于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'

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题