| From: | Russell Smith <mr-russ(at)pws(dot)com(dot)au> |
|---|---|
| To: | Yi Zhao <yi(dot)zhao(at)alibaba-inc(dot)com> |
| Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: can someone help me to make a sql more pretty and more concise? |
| Date: | 2008-11-13 08:27:53 |
| Message-ID: | 491BE509.5020006@pws.com.au |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Yi Zhao wrote:
> 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'
>
How about;
SELECT a, b, count(1), sum(c) FROM mytable WHERE id = (select id from
temptable where
tname = 'df' ) and stype = 'def' and range = 'afk' GROUP BY 1,2;
Russell.
> !!!!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 | Markus Wollny | 2008-11-13 09:32:42 | Re: Suboptimal execution plan for simple query |
| Previous Message | Klint Gore | 2008-11-13 06:00:31 | Re: exception |