Mysql 选择count(*)和count(*),其中在单个查询中列不为null
我有两张表,员工和门店员工将分配某些门店。他的职责是填写门店中门店的地址。我在db中有大约40K个门店 我想得到所有商店的数量和商店的数量在地址填写Mysql 选择count(*)和count(*),其中在单个查询中列不为null,mysql,sql,database,Mysql,Sql,Database,我有两张表,员工和门店员工将分配某些门店。他的职责是填写门店中门店的地址。我在db中有大约40K个门店 我想得到所有商店的数量和商店的数量在地址填写 $sql = "select count(*) from stores"; 上面的查询将返回所有存储的计数如何在同一查询中获得地址填充存储的计数,而不是 $sql = "select count(*) from stores where address is not null" 您似乎是SQL新手。您可以使用count()轻松计算列的非空值:
$sql = "select count(*) from stores";
上面的查询将返回所有存储的计数如何在同一查询中获得地址填充存储的计数,而不是
$sql = "select count(*) from stores where address is not null"
您似乎是SQL新手。您可以使用
count()
轻松计算列的非空值:
学习SQL的最好祝愿。使用sum()
代替count()
试试看:
select count(*) as count_all , SUM(if(address is not null, 1, 0)) AS count2
from stores
不需要这种复杂情况<代码>计数(列)是一个人所需要的全部。
select count(*) as count_all , SUM(if(address is not null, 1, 0)) AS count2
from stores