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
Post a Comment