knowledge-database (beta)

Current group: pgsql.sql

Question about a select

Question about a select  
Kretschmer Andreas
 Re: Question about a select  
Harald Fuchs
From:Kretschmer Andreas
Subject:Question about a select
Date:Sat, 22 Jan 2005 16:56:11 +0100
Hi,

I have a table with this columns: machine, date and area.

Now i need a view with machine an week, calculated from date, and
sum(area), where date between CURRENT_DATE and now+N days.
Okay, this is not the problem, it works fine.

(the original table and the view is more complex)


The problem is, i need also rows for machine and week with no entrys in
the table. For this rows the sum(area) shold be NULL ore 0.
In other words: for every machine i need M rows, and M must be constant.



Regards & Thx, Andreas
--
Diese Message wurde erstellt mit freundlicher Unterstützung eines freilau-
fenden Pinguins aus artgerechter Freilandhaltung. Er ist garantiert frei
von Micro$oft'schen Viren. (#97922 http://counter.li.org) GPG 7F4584DA
Was, Sie wissen nicht, wo Kaufbach ist? Hier: N 51.05082°, E 13.56889° ;-)

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
From:Harald Fuchs
Subject:Re: Question about a select
Date:23 Jan 2005 16:37:47 +0100
In article <20050122155611.GA6592@kaufbach.delug.de>,
Kretschmer Andreas writes:

> Hi,
> I have a table with this columns: machine, date and area.

> Now i need a view with machine an week, calculated from date, and
> sum(area), where date between CURRENT_DATE and now+N days.
> Okay, this is not the problem, it works fine.

> (the original table and the view is more complex)


> The problem is, i need also rows for machine and week with no entrys in
> the table. For this rows the sum(area) shold be NULL ore 0.
> In other words: for every machine i need M rows, and M must be constant.

Week values don't automagically spring into existance when there are
no corresponding entries in your table. Use a set-returning function
for generating the week values you're interested in, and left-join
your table to the SRF.


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
   

Copyright © 2006 knowledge-database   -   All rights reserved