Skip site navigation (1) Skip section navigation (2)

Re: Help with a query, please

From: Vijay Deval <deval(at)giaspn01(dot)vsnl(dot)net(dot)in>
To: Timo Tuomi <tt(at)sllpilots(dot)fi>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Help with a query, please
Date: 2001-03-19 03:34:12
Message-ID: 3AB57E34.1E0F8A91@giaspn01.vsnl.net.in (view raw or flat)
Thread:
Lists: pgsql-novice
Dear Timo

SELECT (test1.i+test2.i) as sum, c as c
FROM test1,test2
WHERE tes1.c=test2.c

UNION

SELECT * 
FROM test1,test2
WHERE ttest1.c != test2.c;

This in theory should give the answer you are looking for. Can work out
exact syntax and mail again in a couple of days.

Vijay

Timo Tuomi wrote:
> 
> testdb=>
> testdb=> select * from test1;
> 
> c|i
> -+-
> A|2
> B|3
> C|4
> (3 rows)
> 
> testdb=> select * from test2;
> 
> c|i
> -+-
> A|6
> C|7
> (2 rows)
> 
> testdb=>
> 
> I'd like to get (test1.i + test2.i) like this:
> 
> c|sum
> -+---
> A|8
> B|3
> C|11
> 
> i.e. to sum the rows but if one of the rows doesn't exist on one of the
> tables then print just the existing row. How can I do this?
> 
> Thanks in advance,
> Timo T.



In response to

pgsql-novice by date

Next:From: Luke Tudor - RSGDate: 2001-03-19 10:44:36
Subject: check_foriegn_key TO FOREIGN KEY.
Previous:From: Louis BertrandDate: 2001-03-19 01:43:41
Subject: Re: installing/running ODBC

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group