Re: Ideas for query - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: Ideas for query
Date
Msg-id 4E96DA33.1050100@iol.ie
Whole thread Raw
In response to Ideas for query  (Steve Clark <sclark@netwolves.com>)
Responses Re: Ideas for query
List pgsql-general
On 13/10/2011 12:17, Steve Clark wrote:
> Hello List,
>
> I am a not very experienced writing sql and I have a problem I can't
> readily solve, so
> I was hoping to get some help from this great list.
>
> Here is my problem I have a table that has event data about the status
> of units in the field. It has
> many kinds of events one of which has down time information. I have
> written a query to extract that
> information and calculate the % downtime. The problem I am having is
> that if the unit was never down
> I don't see it in my query, I would like to be able to somehow report it
> as 100% up.

The way I'd approach this is to do a LEFT OUTER JOIN between the units
table and the events table, with the units on the left of the join: this
way any particular unit will always appear in the result set, and if
there are no corresponding rows in the events table then you know that
the unit had 100% uptime.

HTH.

Ray.


--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

pgsql-general by date:

Previous
From: Ivan Voras
Date:
Subject: Bulk processing & deletion
Next
From: Alban Hertroys
Date:
Subject: Re: Bulk processing & deletion