code_junkie

SQL aggregate functions

Nov 14th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. SELECT p.[name]
  2. FROM products p
  3. WHERE p.product_id in (SELECT s.product_id
  4. FROM productsales s
  5. WHERE s.[date] between @dateStart and @dateEnd
  6. GROUP BY s.product_id
  7. HAVING Sum(s.quantity) > @X )
  8.  
  9. HAVING (Sum(s.quantity*s.price)) > @X
  10.  
  11. SELECT p.name from products p
  12. WHERE p.product_id IN
  13. (SELECT product_id from
  14. (SELECT product_id, (quantity * price) as total
  15. FROM productsales WHERE date between @dateStart and @dateEnd) as s
  16. GROUP by s.product_id
  17. HAVING sum(total) > @x)
Add Comment
Please, Sign In to add comment