sql命令求助

[复制链接]
查看11 | 回复1 | 2011-1-12 16:27:34 | 显示全部楼层 |阅读模式
表1:
id,guestid,amount,allscore
1
11
2500
25
2
12
3200
32
表2:
id,guestid,reducescore
1
11
1000
2
11
800
要求查询表1的所有内容,并且显示每个guestid的所有reducescore的总和,比如查询guestid=11的时候,显示如下数据:
id,guestid,amount,allscore,reducescore
1
11
2500
25
1800

回复

使用道具 举报

千问 | 2011-1-12 16:27:34 | 显示全部楼层
select guestid,amount,allsore,(select sum(redurescore) from table_2 b where b.guestid = a.guestid) from table_1 a
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行