Laravel mysql如何在同一个查询中计算多个表的字段

时间:2017-10-26 05:35:36

标签: mysql laravel-5

我有三个名为users的mysql表,' clients'和' products'。我想算上这个' id'同一查询中每个表的字段。可能吗?请帮我。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

请发表声明

SELECT u.total_users, c.total_clients, p.total_products (
 SELECT COUNT(id) as total_users FROM users
) as u,
(
  SELECT COUNT(id) as total_clients FROM clients
) as c,
(
   SELECT COUNT(id) as total_products FROM products
) as p