我表中的数据
item
item_id name
1 ball
2 cap
3 bat
order
order_id date time
1 06/01/2013 15:12
2 12/01/2013 11:10
3 06/01/2013 23:10
4 23/01/2013 10:55
orderform
order_id item_id quantity
1 1 2
1 3 4
2 1 1
3 2 3
3 1 2
3 3 1
4 1 2
目前我正在使用以下 sql 查询:
SELECT
order_id,
group_concat(txt) AS txt,
date,
time
FROM (
SELECT
orderform.order_id AS order_id,
order.date AS date,
order.time AS time,
CONCAT(orderform.quantity, ' x ',item.name) AS txt
FROM order orderform
LEFT JOIN item ON orderform.item_id = item.item_id
) AS baseview
GROUP BY order_id
我明白了,日期和时间与 id 不同步。
order_id name date time
1 2 x ball,4 x bat 06/01/2013 15:12
2 ball 06/01/2013 23:10
3 3 x cap,2 x ball,bat 06/01/2013 15:12
4 2 x ball 06/01/2013 15:12
它应该看起来像这样。我应该在此查询中为时间和日期做另一个子选择吗?感谢帮助。
order_id name date time
1 2 x ball,4 x bat 06/01/2013 15:12
2 ball 12/01/2013 11:10
3 3 x cap,2 x ball,bat 06/01/2013 23:10
4 2 x ball 23/01/2013 10:55
感谢帮助。