Created
September 30, 2013 19:10
-
-
Save cdeutsch/6768605 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT ISNULL(NULLIF(ca.Value, ''), cc.Email) AS 'Company', | |
SUM([OrderTotal]) as Total, | |
SUM([OrderTotal]-RefundedAmount) as AdjustedTotal | |
FROM [dbo].[Nop_Order] oo | |
INNER JOIN Nop_Customer cc on oo.CustomerID = cc.CustomerID | |
LEFT OUTER JOIN Nop_CustomerAttribute ca on cc.CustomerId = ca.CustomerId and ca.[Key] = 'Company' | |
WHERE RefundedAmount < OrderTotal | |
AND OrderTotal > 0 | |
GROUP BY ISNULL(NULLIF(ca.Value, ''), cc.Email) | |
ORDER BY AdjustedTotal DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment