Search Postgresql Archives

can someone help me to make a sql more pretty and more concise?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux