2014-05-19 147 views
-3

我有兩張表employee和stores員工會有一定的店鋪分配他的職責是填寫店裏的店鋪地址table我有40k店鋪分貝select count(*)and count(*)where column is not null in single query

我想得到所有商店的數量和地址填補商店的數量。

$sql = "select count(*) from stores"; 

上面的查詢將返回所有STORS的數量如何獲得地址填寫門店數量在同一查詢,而不是

$sql = "select count(*) from stores where address is not null" 

回答

5

你似乎是新的SQL。您可以輕鬆地使用計算一個COUNT()列的非NULL值:學習SQL

select count(*), count(address) 
from stores; 

最良好的祝願。

0

使用sum()代替count()

試一下:

select count(*) as count_all , SUM(if(address is not null, 1, 0)) AS count2 
from stores 
+0

無需這種併發症。 'COUNT(列)'是所有需要的。 –

相關問題