0

我想显示两列汇总数据。

  • table1- 统计所有id与表中id相同的show_users字段。
  • table2- 将 id 与表中 id 相同的所有值相加show_users

这是我的查询:

SELECT show_users.id, COUNT(`table1`.id) as sum_fields , SUM(`table2`.count) as count_all
FROM `show_users` 
LEFT JOIN `table1` ON `show_users`.id = `table1`.id
LEFT JOIN `table2` ON `show_users`.id = `table2`.id
GROUP by show_users.id 
ORDER BY sum_fields DESC

结果table2很好,但table1计数不是正确的值......这是为什么呢?

4

1 回答 1

1
SELECT show_users.id, COUNT(DISTINCT `table1`.id) as sum_fields , SUM(`table2`.count) as count_all
于 2012-04-08T06:28:11.460 回答