鍍金池/ 問(wèn)答/數(shù)據(jù)庫(kù)  網(wǎng)絡(luò)安全/ mysql sql語(yǔ)句求助:如何實(shí)現(xiàn)如下訂單列表頁(yè)面,有涉及多個(gè)商品的效果?

mysql sql語(yǔ)句求助:如何實(shí)現(xiàn)如下訂單列表頁(yè)面,有涉及多個(gè)商品的效果?

訂單表:order
id    sn    userid
1    s1    u1
2    s2    u2
3    s3    u3

訂單商品表:order_goods
id    orderid        goodsid
1    1        1
2    2        2
3    3        3
4    3        4
5    3        5

商品表:goods
id    title
1    面包    
2    牛奶
3    西瓜
4    葡萄
5    桔子

想要實(shí)現(xiàn)的效果如下:
訂單列表頁(yè)面:

訂單編號(hào):s1
訂購(gòu)商品:面包


訂單標(biāo)號(hào):s2
訂購(gòu)商品:牛奶


訂單標(biāo)號(hào):s3
訂購(gòu)商品:西瓜
訂購(gòu)商品:葡萄
訂購(gòu)商品:桔子


回答
編輯回答
背叛者

select a.sn,group_concat(c.title) as goodslist from order a left join order_goods b on a.sn = b.orderid left join goods c on b.goodsid = c.id group by a.sn

不知道你的sn是不是就是orderid

2017年12月21日 03:50