Connecting Tech Pros Worldwide Help | Site Map

Returning 0, possibly OUTER JOIN???

Newbie
 
Join Date: Feb 2008
Posts: 1
#1: Feb 19 '08
Hi guys,

I have the following query:

Expand|Select|Wrap|Line Numbers
  1. (SELECT extract(hour from request_time) || ':00-' || ((extract(hour from request_time))+1) || ':00' AS time, count(*) as hits
  2. FROM log_request 
  3. GROUP BY extract(hour from request_time)
  4. ORDER BY extract(hour from request_time))
  5. UNION ALL
  6. (SELECT 'Total', count(*)
  7. FROM log_request);
Which returns an hourly time slot and the amount of times that that hourly slot has appeared, i.e.

00:00-01:00 | 4
10:00-11:00 | 10
Total | 14

Now I want to modify this query so that even if a hourly time slot does not appear in the database to still return it with a value of 0, i.e.

00:00-01:00 | 4
01:00-02:00 | 0

Now it has suggested to me that this may be possible by creating another table called hours and in this table just have a single value for each time slot, i.e. 0 for 00:00-01:00, 1 for 01:00-02:00 and then doing an outer join but so far I have been unsuccessful.

Could anyone suggest a possible solution?

Thanks in advance, Scott.
Reply


Similar PostgreSQL Database bytes