search

Home  >  Q&A  >  body text

mysql - sql 分组查询问题。。

表1

表2

查询语句和结果

结果只显示3条数据,我要显示product表的所有数据,怎么回事?

迷茫迷茫2786 days ago657

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 15:09:04

    Please write like this, the reason for this is improper use of group by
    select p.id,p.productname,p.productcode,p.price,l.num from p
    left join (select pid, sum(num) as num from wlms_stock group by pid) l on p.id = l.pid

    reply
    0
  • 迷茫

    迷茫2017-04-17 15:09:04

    group by should be placed after line 29

    reply
    0
  • Cancelreply