我有一些sql表
+----+------+--------+------------+------------+
| id | code | name | Instructor | PlanePilot |
+----+------+--------+------------+------------+
| 1 | 001 | sasha | N | N |
| 2 | 002 | sasha2 | Y | N |
| 3 | 003 | sasha3 | N | Y |
| 4 | 004 | sasha4 | Y | Y |
| 5 | 005 | sasha5 | Y | Y |
| 6 | 006 | sasha6 | N | N |
| 7 | 007 | sasha7 | Y | N |
| 8 | 008 | sasha8 | Y | N |
+----+------+--------+------------+------------+
我想通过( Instructor , PlanePilot )将其全部排序到 PHP 数组
我的结果是我想要得到一些 php 数组,例如:
$array =[
withoutInstructorPLANEPilot:[sasha,sasha6],
Instructor:[sasha2,sasha4,sasha5,sasha7,sasha8],
PlanePilot:[sasha3,sasha4,sasha5]
]
如果没有 3 个选择查询,例如:
SELECT * FROM mytable where Instructor= 'Y'
我想用 1 个查询来完成并将其转换为 PHP 数组
最佳答案
这是你想要的吗?
select group_concat( (case when Instructor = 'N' and PlanePilot = 'N' then name end) ) as neither,
group_concat( (case when Instructor = 'Y' then name end) ) as instructors,
group_concat( (case when PlanePilot = 'Y' then name end) ) as planepilots
from t;
关于php - GROUP BY ENUM 到数组 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42190709/