将这两个SQL语句合并为一个的最佳方式是什么?我尝试过使用联盟,但似乎无处可去。将这两个SQL语句合并为一个
select id as id from likes where type=1;
select sum(votes) as votes from likes where parent=id;
这里是likes
表:
id type parent country votes
1 1 0 US 0
2 2 1 US 6 // This +
19 3 1 US 3 // This
3 3 2 US 3
7 3 2 US 3
4 10 3 US 1
5 10 3 US 1
6 10 3 US 1
10 10 7 US 1
9 10 7 US 1
8 10 7 US 1
20 10 19 US 1
21 10 19 US 1
22 10 19 US 1
这是我想要达到的效果:
id | votes
---------------
1 | 9
他们做不同的事情。你想达到什么目的? –
我已经更新了表格和我正在尝试完成的问题。 – Norman