使用SQL创建财务报告

时间:2017-08-14 06:37:23

标签: sql

我想使用select语句创建财务报告,例如:我的开始月份是2000年4月,结束月份是2001年3月,我该怎么做?

SELECT  monthList.MonthName ,transcation.id,transaction.amount(
SELECT 10 ordby, 'January' MonthName 
UNION SELECT 11, 'February' 
UNION SELECT 12, 'March'
UNION SELECT 1, 'April' 
UNION SELECT 2,'May'
UNION SELECT 3,'June'
UNION SELECT 4,'July' 
UNION SELECT 5,'August' 
UNION SELECT 6,'September'
UNION SELECT 7,'October' 
UNION SELECT 8,'November' 
UNION SELECT 9,'December') monthList 
left  JOIN (select YEAR(Date) [Year], MONTH(Date) [Month],DATENAME(MONTH,Date) [Month Name],sum(Amount)as amount 
FROM transaction 
where id=2 GROUP BY YEAR(Date), MONTH(Date),DATENAME(MONTH, Date) ) as t on t.[Month Name]=monthList.[Month Name])

0 个答案:

没有答案