Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Some thing is throwing me out here. I want to select top 5 sales by each
- customer. When i used select top5 it's giving me just first five results.
- I'm not sure how to do it. Any Suggestions would be great helpful.Thanks
- i'm not sure where i need to modify here
- select Company_Name,customer_name,sum(Total_Amount) as [Total Sales
- amount],qrtr
- from(
- SELECT Corp100006.HdrCode AS Hdr_Code
- , Corp100006.HdrName AS Company_Name
- , Acct100006.HdrCode AS Acct10000HdrCode
- , Rem100006.HdrName AS Customer_Name
- , BD100006.Period AS Period,
- convert( float, BD100006.Amount*-1) AS Total_Amount,
- CASE
- WHEN MONTH( Period) <= 3 THEN 'Q1'
- WHEN MONTH(Period) > 3 AND MONTH(Period) <= 6 THEN 'Q2'
- WHEN MONTH(Period) > 6 AND MONTH(Period) <= 9 THEN 'Q3'
- WHEN MONTH(Period) >= 10 THEN 'Q4' ELSE '' END AS Qrtr
- FROM ( ( ( ( glBal0001000060Key Root
- INNER JOIN fbMasHdr Corp100006 ON Root.CorpHID = Corp100006.HdrHID )
- INNER JOIN fbMasHdr Acct100006 ON Root.AcctHID = Acct100006.HdrHID )
- INNER JOIN fbMasHdr Rem100006 ON Root.RemitterHID = Rem100006.HdrHID
- )
- LEFT JOIN glBal000100006Data BD100006 ON Root.BalKeyTID =
- BD100006.BalKeyTID )
- where YEAR(Period) = '2017' AND Acct100006.HdrCode in
- ('6332','1161','1311')
- ) sales
- Group by Company_Name,customer_name,qrtr
- order by Company_Name,customer_name,qrtr
Add Comment
Please, Sign In to add comment