我有三张桌子:
orderMaster:
orderNo | status |contactId
--------+--------+---------
100 |Pending |1
200 |Pending |2
300 |Pending |3
orderShirtPant:
orderNo | ShirtorPant |Quantity
--------+-------------+--------
100 |Shirt |2
100 |Pant |3
200 |Shirt |1
200 |Pant |3
300 |Shirt |2
联系人:
contactId | Name
----------+-----------
1 | Mahesh
2 | Anil
3 | Ramesh
想要输出如下:
Name |orderNo| orderDetails
--------+-------+-------------
Mahesh |100 |2 Shirt, 3 Pant
Anil |200 |1 Shirt, 3 Pant
Ramesh |300 |2 Shirt
答案 0 :(得分:0)
请使用以下查询获取结果
select Name,group_concat(Quantity ||' '|| orderShirtPant.ShirtorPant),orderShirtPant.orderNo from contacts,orderShirtPant,orderMaster where contacts.contactId =orderMaster.contactId and orderMaster.orderNo =orderShirtPant.orderNo group by Name;