sql server - SQL Distinct Sum -


select distinct      e.firstname + ' ' + e.lastname [full name],      p.productname,      od.quantity    employees e,          products p,          [order details] od,          orders o      e.employeeid = o.employeeid     , o.orderid = od.orderid     , od.productid = p.productid 

in northwind gives duplicate fullnames , productnames because of quantity changed (because of date shipped each time).

i want present name specific productname total quantity , not divided.

you need use group by sum:

select     e.firstname + ' ' + e.lastname [full name],      p.productname,      sum(od.quantity) [quantity] employees e inner join orders o     on o.employeeid = e.employeeid inner join [order details] od     on od.orderid = o.orderid inner join products p     on p.productid = od.productid group     e.firstname + ' ' + e.lastname,     p.productname 

note, need stop using old-style join syntax.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -