MySQL(表):
+----+------+
| id | text |
+----+------+
| 1 | |
+----+------+
| 2 | blah |
+----+------+
| 3 | |
+----+------+
| 4 | blah |
+----+------+
| 5 | blah |
+----+------+
PHP:
$a = mysql_query("SELECT COUNT(*) AS count1 FROM `table`");
$b = mysql_fetch_assoc($a);
echo $b['count1'];
输出:
5
但是,如果可能的话,我还想在同一个查询中计算填充的文本字段。
结果:
5 in total
3 with filled text fields
最佳答案
SELECT COUNT(*) AS `total`, SUM(IF(`text` <> "",1,0)) AS `non_empty` FROM `table`
关于php - MySQL,统计一个表中 "filled"字段的个数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4730370/