使用group_concat进行Mysql查询

时间:2014-08-11 15:50:02

标签: mysql group-concat

我使用以下查询:

SELECT SQL_CALC_FOUND_ROWS o.*, 
  CONCAT_WS(' ',u.first_name,u.middle_name,u.last_name) AS order_name ,
  u.email as order_email,
  pm.payment_name AS payment_method,
  u.vm_findus AS vm_findus,
  voi.order_item_name AS productname 
FROM orders as o 
LEFT JOIN order_userinfos as u 
  ON u.order_id = o.order_id 
  AND u.address_type="BT" 
LEFT JOIN order_items as voi 
  ON voi.order_id = o.order_id 
LEFT JOIN paymentmethods_nl_nl as pm 
  ON o.paymentmethod_id = pm.paymentmethod_id
WHERE ( o.vendor_id = "1" )
ORDER BY created_on DESC 
LIMIT 0, 30

我得到了这个结果:

Order number    |   Name    |   Email           |   Order ID    | Product Name
123             |   user1   |   user1@test.com  |   2           | product1
123             |   user1   |   user1@test.com  |   2           | product2
369             |   user2   |   user2@test.com  |   1           | product3

但我想跟随结果:

Order number    |   Name    |   Email           |   Order ID    | Product Name
123             |   user1   |   user1@test.com  |   2           | product1, product2
369             |   user2   |   user2@test.com  |   1           | product3

我怎样才能得到这个结果?

0 个答案:

没有答案