gpt4 book ai didi

php - mysql group_concat 里面 while

转载 作者:行者123 更新时间:2023-11-29 02:29:19 28 4
gpt4 key购买 nike

我有这张乘客表日期:

enter image description here

这意味着在 Reservation 000004 中,有两个行程,分别是 Itinerary 0000010 (AAC Hangar - Anvaya Cove)0000011 (Anvaya Cove - AAC Hangar ),并且在每个行程中,有两名乘客(0000007 (taiga)0000011 riyuuji0000010 AAC Hangar - Anvaya Cove 的乘客,而0000008 minori0000012 ami0000011 Anvaya Cove - AAC Hangar 的乘客。

我正在尝试使用 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 吗?我知道这将涉及 while 语句,但截至目前我仍然无法获得所需的输出。请帮忙。

最佳答案

您需要使用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

关于php - mysql group_concat 里面 while,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15540561/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com