我有两个表,即地点和飞行员。我一直试图根据location_id获取数据,即选择按日期(日程安排日期)按照特定location_id顺序飞行的飞行员。问题与分组和按内部连接的条款
我正在使用group by,因为我只需要不同的驾驶员来显示。
select B.*,
A.rather_to_be_flying_now,
A.here_now,
A.flying,
A.when,
A.my_favorite,
A.start,
A.end,
A.Locationid
from locations A
inner join pilots B
on A.Pilotid=B.pilot_id
where A.VenueID='$venueid'
and (A.flying='1' or A.here_now='1')
group by A.Pilotid
ORDER BY A.start
如果我不包含group by子句,该查询很有用。它通过条款
与group by子句
返回以下结果
与出组但上面的表格显示了错误的顺序,因为输出必须返回启动时间设为针对pilotid 1的2013-01-24 02:00:00(时间顺序)。
尝试将'A.start'更改为'MIN(A.start)' – datasage
感谢@datasage它的工作。 –
我有另一个问题,如果我使用MIN(A.start),其余的列值被改变。 –