Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. select p.ProductId
  2. ,sum(od.Quantity) as TotalQuantity
  3. from Products p
  4. join [Order Details] od
  5. on p.ProductId=od.Productid
  6. group by p.ProductId
  7.  
  8. select p.productid
  9. ,p.ProductName
  10. , sum(od.quantity) as TotalQuantity
  11. from products p
  12. join [Order details] od
  13. on p.productid=od.productid
  14. group by p.productid
  15.  
  16. Msg 8120, Level 16, State 1, Line 1
  17. Column 'products.ProductName' is invalid in the select list because
  18. it is not contained in either an aggregate function or the GROUP BY clause.`
  19.  
  20. select p.productid, p.ProductName, sum(od.quantity) as TotalQuantity from
  21. products p join [Order details] od on p.productid=od.productid
  22. group by p.productid, p.ProductName
  23.  
  24. select p.productid
  25. , min(p.ProductName) as ProductName
  26. , sum(od.quantity) as TotalQuantity
  27. from products p
  28. join [Order details] od
  29. on p.productid=od.productid
  30. group by p.productid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement