这是我的疑问:
SELECT (SELECT COUNT(`id`) FROM `table1` WHERE `id` = '1') AS `count1`,
(SELECT COUNT(`id`) FROM `table2` WHERE `id` = '1') AS `count2`,
(SELECT COUNT(`id`) FROM `table3` WHERE `id` = '1') AS `count3`
如何获得count1, count2, count3
的总和?
我有什么方法可以在上面的查询中
答案 0 :(得分:4)
不确定。只需将值加在一起:
SELECT (SELECT COUNT(`id`) FROM `table1` WHERE `id` = '1') +
(SELECT COUNT(`id`) FROM `table2` WHERE `id` = '1') +
(SELECT COUNT(`id`) FROM `table3` WHERE `id` = '1') AS `sum` ...