From: | Yi Zhao <yi(dot)zhao(at)alibaba-inc(dot)com> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | can someone help me to make a sql more pretty and more concise? |
Date: | 2008-11-13 01:21:26 |
Message-ID: | 1226539286.3855.12.camel@localhost.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I want to select some column(a, b) from the table with the specified
condition, so, i can do like this:
select a, b from mytable where id = (select id from temptable where
tname = 'df' ) and stype = 'def' and range = 'afk'
!!!!but, I want the result contains a sum(c) and a count value extra,
so, I use the sql below:
select a, b,
(select count(1) from mytable where id =
(
select id from temptable where tname = 'df'
) and stype = 'def' and range = 'afk'
),
(select sum(c) from mytable where id =
(
select id from temptable where tname = 'df'
) and stype = 'def' and range = 'afk'
)
from mytable where id = (
select id from temptable where tname = 'df'
) and stype = 'def' and range = 'afk';
can someone help me to make this sql statement above more pretty and more concise?
From | Date | Subject | |
---|---|---|---|
Next Message | hendra kusuma | 2008-11-13 02:04:49 | Stored function - send array as parameter to stored function |
Previous Message | Guy Rouillier | 2008-11-13 00:47:15 | Re: Upgrading side by side in Gentoo |