0

我需要搜索特定开发者制作的游戏的总和。我有两张桌子:

 _____________________________
|____________GAMES____________|
| Id | Title | id_dev |  hits |
| 01 | abc   |    1   |   20  |
| 02 | xyz   |    2   |   15  |
| 03 | cde   |    1   |   9   |

 _______________
|__DEVELOPERS___|
| Id |    Title |
| 01 |    poi   |
| 02 |    asd   |
| 03 |    qwe   |

我希望结果格式为Developers title 40,其中 40 是具有此开发人员 ID 的游戏的所有点击数的总和。我该怎么办?

SELECT developers.title, COUNT(count) AS total FROM (SELECT COUNT(games.hits) AS count
FROM games
GROUP BY id_dev
HAVING count > 1) as A
FROM developers
JOIN games
WHERE developers.id = games.id_dev
4

1 回答 1

4

这是一个简单的连接和聚合,所以你把事情复杂化了:

select d.id, d.title, sum(g.hits)
from games g join
     developers d
     on g.id_dev = d.id
group by d.id, d.title;
于 2013-07-18T19:21:52.150 回答