多谢你能抽出宝贵时间帮我编写程序。
你给我的语句在我的计算机上我发运行:
1。isnull()函数通不过。
2。full join 通不过。
你能否帮我编一个子查询的语句??万分感谢!!!
DECLARE @tbl_a TABLE(dt DATETIME, income DECIMAL(5,2))
INSERT INTO @tbl_a SELECT '2007-05-12',10
UNION ALL SELECT '2007-05-12',20
UNION ALL SELECT '2007-05-12',10
UNION ALL SELECT '2007-08-20',30
UNION ALL SELECT '2007-08-20',30
UNION ALL SELECT '2007-09-17',10
UNION ALL SELECT '2007-11-16',10
DECLARE @tbl_b TABLE(dt DATETIME, payout DECIMAL(5,2))
INSERT INTO @tbl_b SELECT '2007-05-12',5
UNION ALL SELECT '2007-05-12',4
UNION ALL SELECT '2007-06-19',10
UNION ALL SELECT '2007-08-20',7
UNION ALL SELECT '2007-08-20',9
UNION ALL SELECT '2007-09-17',18
UNION ALL SELECT '2007-03-15',11
SELECT CONVERT(VARCHAR(10),ISNULL(t1.dt,t2.dt),120) '每日日期',
ISNULL(每日收入额,0)-ISNULL(每日支出额,0) AS '余额'
FROM (SELECT dt,SUM(income) AS '每日收入额'
FROM @tbl_a
GROUP BY dt) AS t1
FULL OUTER JOIN
(SELECT dt,SUM(payout) AS '每日支出额'
FROM @tbl_b
GROUP BY dt) AS t2
ON t1.dt=t2.dt