2

This my first select query

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 

This is my second select query

  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 

So when I join these two

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 ;

I get the time, day, zone_id twice instead of the joined one. Any help is appreciated.

1 Answer 1

1

Which is not very surprisingly since your subquery joins are wrapped in an outer query which does SELECT * you want something like

SELECT A.time, A.day, A.zone_id, booking_trips /*, ... REST OF THE REQUIRED COLUMNS */ 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 ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.