我有以下两个SQL选择:两个SQL的结果相结合,选择
select
u.ID, name, "Desc", sum(pp.amount) as paid
from
[dbo].[Users] u, [dbo].[UserTypes] ut, [dbo].[PlayerPayments] pp
where
u.UserTypeID = ut.ID
and u.ID = pp.UserID
group by
u.ID, Name, "Desc";
select
u.ID,name, "Desc", sum(ga.GamePrice) as owed, count(ga.ID) as gamesplayed
from
[dbo].[Users] u,[dbo].[UserTypes] ut, [dbo].[Games] ga, [dbo].[GamePlayers] gp
where
u.UserTypeID = ut.ID
and u.ID = gp.UserID
and gp.GameID = ga.ID
group by
u.ID, Name, "Desc";
以及返回下面的结果看起来像如下:
我怎么能合并结果一起通过在第一个结果集中添加两列(欠款和游戏玩法)?
[不良习惯踢:使用旧式JOIN](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style- joins.aspx) - 在ANSI - ** 92 ** SQL标准中**旧式*逗号分隔的表*样式列表已替换为* proper * ANSI'JOIN'语法(**超过20年**之前),并且不鼓励使用它 –
哪种RDBMS适用于?请添加一个标签来指定您是使用'mysql','postgresql','sql-server','oracle'还是'db2' - 或者其他的东西。 –