我有这个乘客表日期:
这意味着在预订000004
中,有两个行程是行程0000010 (AAC Hangar - Anvaya Cove)
和0000011 (Anvaya Cove - AAC Hangar)
,每个行程中都有两名乘客(0000007 (taiga)
和{ {1}} 0000011 riyuuji
0000008 minori 0000010 AAC Hangar - Anvaya Cove while
0000012 ami and
0000011 Anvaya Cove - AAC Hangar)的乘客。
我正在尝试使用are passengers of
连接它们,但我只能这样做:
group_concat
结果: $a=mysql_query("select group_concat(pass_name separator ', ') as 'pass' from passengers where reservno = '0000004' order by id asc") or die(mysql_error());
$b=mysql_fetch_array($a);
$c=$b['pass'];
。
但我希望它看起来像这样: taiga, minori, riyuuji, ami
这可以使用taiga, riyuuji / minori, ami
吗?我知道这将涉及group_concat
语句,但截至目前我仍然无法获得所需的输出。请帮忙。
答案 0 :(得分:2)
您需要使用GROUP BY
子句
select group_concat(pass_name separator ', ') as 'pass'
from passengers
where reservno = '0000004'
GROUP BY reservno, id
order by id asc
更新1
SELECT group_concat(`pass` separator ' / ') `pass`
FROM (
select group_concat(pass_name separator ', ') as 'pass'
from passengers
where reservno = '0000004'
GROUP BY reservno, id order by id asc
) s