我有兩個表,即地點和飛行員。我一直試圖根據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),其餘的列值被改變。 –