开发者

SQL Grouping using left join

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜