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

From: Yi Zhao <yi(dot)zhao(at)alibaba-inc(dot)com>
To: Russell Smith <mr-russ(at)pws(dot)com(dot)au>
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 09:44:52
Message-ID: 1226569492.3855.26.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

thanks for ur help,
but, I think that is not my want:D
if you use sum like this, it must be with group by,
what I want is do sum on all columns, not group by.

thanks

regards,

在 2008-11-13四的 19:27 +1100,Russell Smith写道:
> 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?
> >
> >
> >
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jean-Christophe Arnu 2008-11-13 09:49:00 pg_lesslog/pg_standby
Previous Message Andrus 2008-11-13 09:41:35 Re: Upgrading side by side in Gentoo