我有一些sql表格表
>>>extractDups(names)
['John', 'Mike']
我想用GROUP by(Instructor,PlanePilot)将所有内容排序到PHP数组
我的结果我想得到一些像以下的php数组:
+----+------+--------+------------+------------+
| 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 |
+----+------+--------+------------+------------+
如果没有3个选择查询,如何:
$array =[
withoutInstructorPLANEPilot:[sasha,sasha6],
Instructor:[sasha2,sasha4,sasha5,sasha7,sasha8],
PlanePilot:[sasha3,sasha4,sasha5]
]
我想用1个查询做它并将其转换为PHP数组
答案 0 :(得分:1)
这是你想要的吗?
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;