我有一些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 |
+----+------+--------+------------+------------+
我想通过(教练,飞机飞行员(将其全部排序到带有GROUP的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;