2

我正在尝试通过MySQL单个查询获取三个不同表中的简单行数。这是我所拥有的:

SELECT count(s.`id`) AS c1,
       count(g.`id`) AS c2,
       count(r.`id`) AS c3
  FROM table1 s,
       table2 g,
       table3 r

但这不起作用,我认为它将所有三个总数相乘。谢谢您的帮助。

4

1 回答 1

4

如果表没有关系并且无法连接,请尝试以下操作:

SELECT
  (select count(id) from table1) as c1,
  (select count(id) from table2) as c2,
  (select count(id) from table3) as c3
于 2012-12-17T07:57:12.837 回答