Обсуждение: Difficult query (for me)

Поиск
Список
Период
Сортировка

Difficult query (for me)

От
sylfanie@club-internet.fr (Stephane)
Дата:
Hello,

Basicaly I have two tables like this:

Table 1
RecordName Value
a          100
b          100
c          100
d          100
e          100
f          100

Table 2
RecordName Value
a         25
b         50
c         75
g         150
h         150

I would like a query that give me a result like this:
a         75 (100-25)
b         50 (100-50)
c         25
d         100
e         100
f         100
g         -150
h         -150

It is table1-table2.
I could do it for records a,b,c but I do not how to have record which
are only in one of the two tables.
Thanks for your help.
Stephane.



Re: Difficult query (for me)

От
"David Olbersen"
Дата:
Stephane,

Sorry, further reading shows me that I'm dumb and you can already do this.

--------------------------
David Olbersen
iGuard Engineer
11415 West Bernardo Court
San Diego, CA 92127
1-858-676-2277 x2152


> -----Original Message-----
> From: David Olbersen
> Sent: Monday, April 07, 2003 9:32 AM
> To: pgsql-sql@postgresql.org
> Subject: RE: [SQL] Difficult query (for me)
>
>
> Stephane,
>
> SELECT
>   table1.recordname,
>   table1.value - table2.value
> FROM
>   table1,
>   table2
> WHERE
>   table1.recordname = table2.recordname
>
> Right?
>
> --------------------------
> David Olbersen
> iGuard Engineer
> 11415 West Bernardo Court
> San Diego, CA 92127
> 1-858-676-2277 x2152
>
>
> > -----Original Message-----
> > From: Stephane [mailto:sylfanie@club-internet.fr]
> > Sent: Friday, April 04, 2003 12:06 PM
> > To: pgsql-sql@postgresql.org
> > Subject: [SQL] Difficult query (for me)
> >
> >
> > Hello,
> >
> > Basicaly I have two tables like this:
> >
> > Table 1
> > RecordName Value
> > a          100
> > b          100
> > c          100
> > d          100
> > e          100
> > f          100
> >
> > Table 2
> > RecordName Value
> > a         25
> > b         50
> > c         75
> > g         150
> > h         150
> >
> > I would like a query that give me a result like this:
> > a         75 (100-25)
> > b         50 (100-50)
> > c         25
> > d         100
> > e         100
> > f         100
> > g         -150
> > h         -150
> >
> > It is table1-table2.
> > I could do it for records a,b,c but I do not how to have
> record which
> > are only in one of the two tables.
> > Thanks for your help.
> > Stephane.
> >
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> >
>



Re: Difficult query (for me)

От
"David Olbersen"
Дата:
Stephane,

SELECT  table1.recordname, table1.value - table2.value
FROM  table1, table2
WHERE table1.recordname = table2.recordname

Right?

--------------------------
David Olbersen
iGuard Engineer
11415 West Bernardo Court
San Diego, CA 92127
1-858-676-2277 x2152


> -----Original Message-----
> From: Stephane [mailto:sylfanie@club-internet.fr]
> Sent: Friday, April 04, 2003 12:06 PM
> To: pgsql-sql@postgresql.org
> Subject: [SQL] Difficult query (for me)
>
>
> Hello,
>
> Basicaly I have two tables like this:
>
> Table 1
> RecordName Value
> a          100
> b          100
> c          100
> d          100
> e          100
> f          100
>
> Table 2
> RecordName Value
> a         25
> b         50
> c         75
> g         150
> h         150
>
> I would like a query that give me a result like this:
> a         75 (100-25)
> b         50 (100-50)
> c         25
> d         100
> e         100
> f         100
> g         -150
> h         -150
>
> It is table1-table2.
> I could do it for records a,b,c but I do not how to have record which
> are only in one of the two tables.
> Thanks for your help.
> Stephane.
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>