根据mysql中的条件显示计数值

时间:2018-05-09 10:11:33

标签: mysql

根据countries.haveState选择instituteId的计数。如果haveState = 1那么,Count(institutionss.instituteid)基于stateId,如if(institution.stateId =' 1')然后计数Count(institutions.instituteid),否则计算没有stateId的instituteId,如下所示。

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' 

0 个答案:

没有答案