Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 选择count(*)和count(*),其中在单个查询中列不为null_Mysql_Sql_Database - Fatal编程技术网

Mysql 选择count(*)和count(*),其中在单个查询中列不为null

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()轻松计算列的非空值:

我有两张表,员工和门店员工将分配某些门店。他的职责是填写门店中门店的地址。我在db中有大约40K个门店

我想得到所有商店的数量和商店的数量在地址填写

$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