表a(作者表)
author_id
author_name
表b(员额表)
post_id
author_id
表c(收入表)
post_id (post id is not unique)
post_earning
我想生成一份由每位作者的收入组成的报告。
author_id
author_name
total_earning (sum of earnings of all the posts by author)
SELECT
a.author_id,
a.author_name,
sum(post_earnings) as total_earnings
FROM TableA a
Inner Join TableB b on b.author_id = a.author_id
Inner Join TableC c on c.post_id = b.post_id
Group By
a.author_id,
a.author_name
我得到的结果是:
ID user_login total_earnings
2 Redstar 13.99
7 Redleaf 980.18
10 topnhotnews 80.43
11 zmmishad 39.27
13 rashel 1248.34
14 coolsaint 1.66
16 hotnazmul 9.83
17 rubel 0.14
21 mahfuz1986 1.09
48 ripon 12.96
60 KHK 27.81