你可以起訴很多情況下
select agent,
case day when 'Mon' then start end as start_mon,
case day when 'Mon' then `end` end as end_mon,
case day when 'Tue' then start end as start_tue,
case day when 'Tue' then `end` end as end_the,
case day when 'Wed' then start end as start_wed,
case day when 'Wed' then `end` end as end_wed
from your_table
對於剛開在同一行代理的價值,你可以使用一個臨時表和組BT
select agent, max(start_mon), max(end_mon), max(start_tue), max(end_tue), max(start_wed), max(end_web)
from (
select agent,
case day when 'Mon' then start end as start_mon,
case day when 'Mon' then `end` end as end_mon,
case day when 'Tue' then start end as start_tue,
case day when 'Tue' then `end` end as end_the,
case day when 'Wed' then start end as start_wed,
case day when 'Wed' then `end` end as end_wed
from your_table) as t
group by agent;
您只需要1個查詢就可以了。到目前爲止,你有什麼? – jeroen
我每天都想做這樣的事情: 選擇(從日程安排中選擇start_dt,其中day ='Mon')爲'MonStart', (從日程安排中選擇end_dt ='Mon')爲'EndStart'; –
如果會有更多的代理商,「agent2」,「agent3」,該怎麼辦? – RomanPerekhrest