Re: Help with a query, please

Поиск
Список
Период
Сортировка
От Vijay Deval
Тема Re: Help with a query, please
Дата
Msg-id 3AB57E34.1E0F8A91@giaspn01.vsnl.net.in
обсуждение исходный текст
Ответ на Help with a query, please  (Timo Tuomi <tt@sllpilots.fi>)
Список 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.



В списке pgsql-novice по дате отправления:

Предыдущее
От: Louis Bertrand
Дата:
Сообщение: Re: installing/running ODBC
Следующее
От: Luke Tudor - RSG
Дата:
Сообщение: check_foriegn_key TO FOREIGN KEY.