您可以使用row_number()
和聚合:
select shift, max(case when rn = 1 then starttime end) starttime1, max(case when rn = 2 then starttime end) starttime2, max(case when rn = 3 then starttime end) starttime3 from ( select t.*, row_number() over(partition by shift order by starttime) rn from mytable t ) t group by shift