请教sql200数据库 3个表合并成为一个表语句
mnamenormba26167b46112c5477d10066如何用查询语句把上面3个表合并成为下面的这个表?...
mname no rmb
a 26 167
b 46 112
c 54 77
d 100 66
如何用查询语句把上面3个表合并成为下面的这个表? 展开
a 26 167
b 46 112
c 54 77
d 100 66
如何用查询语句把上面3个表合并成为下面的这个表? 展开
1个回答
展开全部
用下面这个语句就行了,Table1-3的表名改成你自己的
SELECT [Table3].[mname], [temp1].[no], [temp2].[rmb]
FROM [Table3]
INNER JOIN (SELECT [id], SUM([no]) AS [NO] FROM [Table1] GROUP BY [id]) AS [Temp1] ON [Table3].[id] = [Temp1].[id]
INNER JOIN (SELECT [id], SUM([rmb]) AS [rmb] FROM [Table2] GROUP BY [id]) AS [Temp2] ON [Table3].[id] = [Temp2].[id]
ORDER BY [Table3].[mname]
SELECT [Table3].[mname], [temp1].[no], [temp2].[rmb]
FROM [Table3]
INNER JOIN (SELECT [id], SUM([no]) AS [NO] FROM [Table1] GROUP BY [id]) AS [Temp1] ON [Table3].[id] = [Temp1].[id]
INNER JOIN (SELECT [id], SUM([rmb]) AS [rmb] FROM [Table2] GROUP BY [id]) AS [Temp2] ON [Table3].[id] = [Temp2].[id]
ORDER BY [Table3].[mname]
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询