【发布时间】:2017-04-30 14:56:45
【问题描述】:
这是我的第一个选择查询
SELECT date_trunc('hour',start_time) as time , extract(day from start_time) as day ,start_zone_id as zone_id, count(*) as booking_trips
FROM public.trip_information_september where trip_type='{BOOKING}' group by date_trunc('hour',start_time ), start_zone_id ,extract(day from start_time) ORDER BY time,start_zone_id
这是我的第二个选择查询
SELECT date_trunc('hour',start_time) as time , extract(day from start_time) as day ,start_zone_id as zone_id, count(*) as booking_trips
FROM public.trip_information_september where trip_type='{NO_INFO}' group by date_trunc('hour',start_time ), start_zone_id ,extract(day from start_time) ORDER BY time,start_zone_id
所以当我加入这两个时
select * from
(SELECT date_trunc('hour',start_time) as time , extract(day from start_time) as day ,start_zone_id as zone_id, count(*) as booking_trips
FROM public.trip_information_september where trip_type='{BOOKING}' group by date_trunc('hour',start_time ), start_zone_id ,extract(day from start_time) ORDER BY time,start_zone_id )A
INNER JOIN
(SELECT date_trunc('hour',start_time ) as time,extract(day from start_time) as day, start_zone_id as zone_id, count(*) as normal_trips
FROM public.trip_information_september where trip_type='{NORMAL}' group by date_trunc('hour',start_time ), start_zone_id ,extract(day from start_time) ORDER BY time,start_zone_id) B
ON A.time=B.time and A.zone_id=B.zone_id and A.day=B.day limit 100 ;
我得到时间、日期、zone_id 两次,而不是加入的一次。 任何帮助表示赞赏。
【问题讨论】:
标签: database postgresql join