查詢1:SQL嵌套查詢
select
PremiumYTDCurrent=Sum((AASI.Inv_Premium)*R.[Percent]),
R.STAFF, L.Description, L.LINE_OF_BUSINESS
from AAS_Invoice AASI,Invoice I,Revenue_Tracking R, Policy P, Line_Of_Business L
where I.Invoice_No=convert(Char,Convert(int,AASI.Inv_Entry_Num))
and I.Invoice=R.Invoice
and I.POLICY=P.POLICY
and L.LINE_OF_BUSINESS=P.LINE_OF_BUSINESS
and AASI.Inv_Acctcur>='201001'
and AASI.Inv_Acctcur<='201004'
and R.Organization=200
and R.Activity_type='Broker'
and R.STAFF=7600
and R.[Percent]>0
group by R.STAFF, L.Description, L.LINE_OF_BUSINESS
問題2:
select
PremiumYTDPrevious=Sum((AASI.Inv_Premium)*R.[Percent]),
R.STAFF, L.Description, L.LINE_OF_BUSINESS
from AAS_Invoice AASI,Invoice I,Revenue_Tracking R, Policy P, Line_Of_Business L
where I.Invoice_No=convert(Char,Convert(int,AASI.Inv_Entry_Num))
and I.Invoice=R.Invoice
and I.POLICY=P.POLICY
and L.LINE_OF_BUSINESS=P.LINE_OF_BUSINESS
and AASI.Inv_Acctcur>='200901'
and AASI.Inv_Acctcur<='200904'
and R.Organization=200
and R.Activity_type='Broker'
and R.STAFF=7600
and R.[Percent]>0
group by R.STAFF, L.Description, L.LINE_OF_BUSINESS
這些2個查詢是除日期週期是相同的。我想要的是有一個查詢,但添加一個字段(PremiumYTDPrevious)。可以做到嗎?
感謝,
島
這一個工程好:)謝謝! – 2011-01-31 14:39:20