can someone help me to make a sql more pretty and more concise? - Mailing list pgsql-general

From Yi Zhao
Subject can someone help me to make a sql more pretty and more concise?
Date
Msg-id 1226539286.3855.12.camel@localhost.localdomain
Whole thread Raw
In response to Re: Upgrading side by side in Gentoo  (Guy Rouillier <guyr-ml1@burntmail.com>)
Responses Re: can someone help me to make a sql more pretty and more concise?
List 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?


pgsql-general by date:

Previous
From: Guy Rouillier
Date:
Subject: Re: Upgrading side by side in Gentoo
Next
From: "hendra kusuma"
Date:
Subject: Stored function - send array as parameter to stored function