我需要如下图所示的来自 6 个查询的报告:![在此处输入图像描述][1]
[1]:http: //i.stack.imgur.com/Lcsiz.png
我的查询#1
SELECT LoanType, SUM(MyOutStanding) AS MyOutStanding, COUNT(NoofFile) AS NoofFile, Status
FROM (SELECT (CASE WHEN loantype = 'Auto Loan' THEN 'Auto Loan'
WHEN loantype = 'Home Loan' THEN 'Home Loan' WHEN loantype = 'Home Mortgage Loan' THEN 'Home Mortgage Loan'
ELSE 'Any Purpose Loan' END) AS LoanType,
SUM(outstanding) AS MyOutStanding, COUNT(clid) AS NoofFile, Status
FROM dbo.RecTestCL GROUP BY loantype, Status) X where Status='Regular'
GROUP BY LoanType, Status order by LoanType, Status
我的查询#2
SELECT LoanType As UC_LoanType, SUM(MyOutStanding) AS UC_Out, COUNT(NoofFile) AS UC_file, Reg_MyOutStanding='',Reg_NoofFile=''
FROM (SELECT (CASE WHEN loantype = 'Auto Loan' THEN 'Auto Loan'
WHEN loantype = 'Home Loan' THEN 'Home Loan' WHEN loantype = 'Home Mortgage Loan' THEN 'Home Mortgage Loan'
ELSE 'Any Purpose Loan' END) AS LoanType,
SUM(outstanding) AS MyOutStanding, COUNT(clid) AS NoofFile, Status
FROM dbo.RecTestCL GROUP BY loantype, Status) X where Status='UC'
GROUP BY LoanType, Status order by LoanType, Status
我的查询#3
SELECT LoanType, SUM(MyOutStanding) AS MyOutStanding, COUNT(NoofFile) AS NoofFile, Status
FROM (SELECT (CASE WHEN loantype = 'Auto Loan' THEN 'Auto Loan'
WHEN loantype = 'Home Loan' THEN 'Home Loan' WHEN loantype = 'Home Mortgage Loan' THEN 'Home Mortgage Loan'
ELSE 'Any Purpose Loan' END) AS LoanType,
SUM(outstanding) AS MyOutStanding, COUNT(clid) AS NoofFile, Status
FROM dbo.RecTestCL GROUP BY loantype, Status) X where Status='SMA'
GROUP BY LoanType, Status order by LoanType, Status
我的查询#4
SELECT LoanType, SUM(MyOutStanding) AS MyOutStanding, COUNT(NoofFile) AS NoofFile, Status
FROM (SELECT (CASE WHEN loantype = 'Auto Loan' THEN 'Auto Loan'
WHEN loantype = 'Home Loan' THEN 'Home Loan' WHEN loantype = 'Home Mortgage Loan' THEN 'Home Mortgage Loan'
ELSE 'Any Purpose Loan' END) AS LoanType,
SUM(outstanding) AS MyOutStanding, COUNT(clid) AS NoofFile, Status
FROM dbo.RecTestCL GROUP BY loantype, Status) X where Status='SS'
GROUP BY LoanType, Status order by LoanType, Status
我的查询#5
SELECT LoanType, SUM(MyOutStanding) AS MyOutStanding, COUNT(NoofFile) AS NoofFile, Status
FROM (SELECT (CASE WHEN loantype = 'Auto Loan' THEN 'Auto Loan'
WHEN loantype = 'Home Loan' THEN 'Home Loan' WHEN loantype = 'Home Mortgage Loan' THEN 'Home Mortgage Loan'
ELSE 'Any Purpose Loan' END) AS LoanType,
SUM(outstanding) AS MyOutStanding, COUNT(clid) AS NoofFile, Status
FROM dbo.RecTestCL GROUP BY loantype, Status) X where Status='DF'
GROUP BY LoanType, Status order by LoanType, Status
我的查询#6
SELECT LoanType, SUM(MyOutStanding) AS MyOutStanding, COUNT(NoofFile) AS NoofFile, Status
FROM (SELECT (CASE WHEN loantype = 'Auto Loan' THEN 'Auto Loan'
WHEN loantype = 'Home Loan' THEN 'Home Loan' WHEN loantype = 'Home Mortgage Loan' THEN 'Home Mortgage Loan'
ELSE 'Any Purpose Loan' END) AS LoanType,
SUM(outstanding) AS MyOutStanding, COUNT(clid) AS NoofFile, Status
FROM dbo.RecTestCL GROUP BY loantype, Status) X where Status='BL'
GROUP BY LoanType, Status order by LoanType, Status