如何计算2个表格中的所有行...
`approved` == '0'
答案 0 :(得分:4)
您需要在联盟上进行聚合:
select sum(subcount) as totalcount
from ( select count(*) as subcount from table1 where approved = 0
union
select count(*) as subcount from table2 where approved = 0 )
还有其他方法,但这会非常清楚地显示您的意图,尤其是以这种方式命名列。
希望这有帮助
答案 1 :(得分:-1)
您可以为每个表执行此操作:
SELECT count(*) FROM table WHERE approved = 0
您可以将其合并为一个查询,但这会变得更复杂。使用子查询或联合。
答案 2 :(得分:-1)
这个答案可以帮到你:
$query = "select count(*)+(select count(*) from table1) as totalrows from table2";