I have 2 tables with related data. One table is for products
and the other price
. In the price table one product may appear several times. How can I r开发者_运维技巧eturn the result by grouping.
Below is my Query but the output is not with Group
SELECT distinct
p.Product,
p.Qty,
MAX(pr.netprice)
FROM Products p
LEFT OUTER JOIN Price pr ON p.Product=pr.Product
WHERE p.brand=''
GROUP BY p.Product, p.Qty
You should probably leave the Qty
out of the group by
, like this:
SELECT p.Product,
MAX(pr.netprice)
FROM Products p
LEFT OUTER JOIN Price pr ON p.Product=pr.Product
WHERE p.brand=''
GROUP BY p.Product
精彩评论