DECLARE @Table1 table ([date] datetime, StartingAum int)
DECLARE @Table2 table ([date] datetime, DepContr int, withdra int)
INSERT @Table1 VALUES ('07/01/2010', 120)
INSERT @Table1 VALUES ('08/01/2010', 220)
INSERT @Table1 VALUES ('09/01/2010', 320)
INSERT @Table2 VALUES ('01/01/2010', 60 , 15)
INSERT @Table2 VALUES ('02/01/2010', 70 , 25)
INSERT @Table2 VALUES ('03/01/2010', 80 , 15)
INSERT @Table2 VALUES ('04/01/2010', 30 , 89)
INSERT @Table2 VALUES ('05/01/2010', 40 , 15)
INSERT @Table2 VALUES ('06/01/2010', 25 , 85)
INSERT @Table2 VALUES ('07/01/2010', 16 , 17)
INSERT @Table2 VALUES ('08/01/2010', 19 , 21)
INSERT @Table2 VALUES ('09/01/2010', 68 , 79)
SELECT
t2.[Date]
,ISNULL(t1.StartingAum, 0) AS StartingAum
,t2.DepContr
,t2.withdra
FROM @Table2 t2
LEFT JOIN @Table1 t1 ON t2.[Date] = t1.[Date]
ORDER BY t2.[Date]
OUTPUT:
Date StartingAum DepContr withdra
----------------------- ----------- ----------- -----------
2010-01-01 00:00:00.000 0 60 15
2010-02-01 00:00:00.000 0 70 25
2010-03-01 00:00:00.000 0 80 15
2010-04-01 00:00:00.000 0 30 89
2010-05-01 00:00:00.000 0 40 15
2010-06-01 00:00:00.000 0 25 85
2010-07-01 00:00:00.000 120 16 17
2010-08-01 00:00:00.000 220 19 21
2010-09-01 00:00:00.000 320 68 79
对您重复询问如何生成结果集是不合适的。从你的[上一个问题](http://stackoverflow.com/questions/3945837/how-to-join-two-tables)学习,甚至在一个小时前就问过。 – 2010-10-15 21:10:15
-1对于类似的问题在时间上如此接近。在IRC(聊天室)中,快速射击Q和A可能更合适。 Google“IRC sql”。你可以在那里进行对话,这可能会非常有帮助。 – orolo 2010-10-15 21:18:04
欢迎来到stackoverflow!有些人有时会有点胡思乱想,只是忽略他们并提出问题。 – 2010-10-15 21:32:42