php - 如何计算所选表中具有空字段的所有记录

标签 php mysql

假设我有四个个表,我只需选择3个表,其数据库名为Records

Records
1.Cases
2.Ballistics
3.Chem
4.Accounts

Cases
id|year|Natureofcase |
0 |    |Repact 1901a |
1 |2003|Repact 1907b |
3 |2004|Repact 1902  |

Ballistics
id|year|Name     |Type  |
0 |2003|         |a-101 | 
1 |    |Silver-A |a-202 |
3 |2005|Red Cap  |      |

Chem
id|year|Identified   |
0 |    |H20+C20      |
1 |2001|Am           |
3 |2009|             |  

所以我们有 6 行包含空表。 我想使用 PHP 显示总和 6。谢谢。任何意见/答案/建议将不胜感激。

最佳答案

请尝试一下

SELECT 
   (SELECT COUNT(*) FROM Cases WHERE year = '' OR Natureofcase = '') +
   (SELECT COUNT(*) FROM Ballistics WHERE year ='' OR Name='' OR Type='') +
   (SELECT COUNT(*) FROM Chem WHERE year='' OR Identified='')
AS total_empty

关于php - 如何计算所选表中具有空字段的所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36830847/

相关文章:

php - sql当月查询

php - Laravel 4 应用程序中的浏览器缓存问题

php - mysql_query 没有按预期工作

mysql - 删除MySQL中两个单词之间的空格

php - MySQL - 仅获取 CVCV 值的最佳方式?

PHP MySQL 插入不起作用,我找不到任何错误

php - Laravel 迁移,检查 hasColumn 但获取 Column Exists MySQL 错误

php - 如何替换 Jms Payment Paypal Bundle 中的文本

php - 如何在mysql中选择前10条记录

php - 数据库表更新不起作用?