列在oracle中排

时间:2017-05-22 17:46:04

标签: sql oracle pivot

我有一张表让表格T1和表中有名字,我想知道Greg和Ammy在不同时间的位置,让我们说在早上6:59之间,早上7点到11点之间:下午59点和中午12:00之后。但是这里有捕获,我想创建一个查询,显示列中的纬度和经度,名为上午6:59,上午7:00 - 晚上11:59,中午12:00之后。

type StringLiteral = keyof typeof StringLiterals;

1 个答案:

答案 0 :(得分:0)

您需要先使用案例陈述将每一行分类为您描述的3个时间段,例如:

select name, lattitude, longitude,
case when date_tm < '20-MAY-17 07:00:00' then '6:59AM'
     when date_tm < '20-MAY-17 12:00:00' then '7:00AM - 11:59PM'
     else '12:00PM' end as time_period
from T1.

然后,您可以转动以将行更改为列:

select *
from
(select name, Lattitude||','|| Longitude  as lat_long,
 case when date_tm < '20-MAY-17 07:00:00' then '6:59AM'
     when date_tm < '20-MAY-17 12:00:00' then '7:00AM - 11:59PM'
     else '12:00PM' end as time_period
from T1)

PIVOT

(
    max(lat_long) for time_period in ('6:59AM','7:00AM - 11:59PM','12:00PM')
);