Re: UNION and rows improperly unified: query optimization question

Поиск
Список
Период
Сортировка
От Jean-Luc Lachance
Тема Re: UNION and rows improperly unified: query optimization question
Дата
Msg-id 3C699C10.4BCB1362@nsd.ca
обсуждение исходный текст
Ответ на UNION and rows improperly unified: query optimization question  (Henry House <hajhouse@houseag.com>)
Список pgsql-sql
Henry,

How about:

SELECT t.postdate, t.person,  case where g.amt >= 0 then g.amt else '0.00' end as debit,  case where g.amt < 0 then
'0.00'else -g.amt end as credit, t.descr,
 
t.num 
FROM transact t, gl_entry g
ORDER BY postdate;


Henry House wrote:
[...] 
> SELECT postdate, person, debit, credit, descr, num FROM (
>                 SELECT t.postdate, t.person, abs(g.amt) AS debit, '0.00' AS credit, t.descr, t.num, g.id AS gid
>                 FROM transact t, gl_entry g ' +
>                 WHERE t.id = g.transact_id AND g.amt >= 0
>         UNION
>                 SELECT t.postdate, t.person, '0.00' AS debit, abs(g.amt) AS credit, t.descr, t.num, g.id AS gid
>                 FROM transact t, gl_entry g
>                 WHERE t.id = g.transact_id AND g.amt < 0
> ) AS subselect ORDER BY postdate
> 
> I would like to get rid of the outer SELECT, if possible.
> 
> --
> Henry House
> The attached file is a digital signature. See <http://romana.hajhouse.org/pgp>
> for information.  My OpenPGP key: <http://romana.hajhouse.org/hajhouse.asc>.
> 
>   ------------------------------------------------------------------------
>    Part 1.2Type: application/pgp-signature


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

Предыдущее
От: Oleg Lebedev
Дата:
Сообщение: Re: pg_atoi error
Следующее
От: Srikanth Rao
Дата:
Сообщение: remove