Need query to separate rows by one field's value

Поиск
Список
Период
Сортировка
От Jeff Boes
Тема Need query to separate rows by one field's value
Дата
Msg-id 021a9dcef9be53a70a73251b8fe9080a@news.teranews.com
обсуждение исходный текст
Список pgsql-sql
Here's a query challenge for you. Given:

table foo (  a integer primary key,  b integer check (b > 0))

with a limited number of rows (say, <= 10). Values in column "a" are 
unique (obviously). Values in column "b" are not.

I want to find a set of values for "a" such that the sum of "b" values 
is as close to one-half of the total sum of "b" over all rows. That is,

select 2.0*sum(b) from foo
where a in (...);

would be approximately the same as

select sum(b) from foo;

Likewise,

select 2.0*sum(b) from foo
where a NOT in (...);

would be approximately that value, too.


-- 
Jeff Boes                                      vox 269.226.9550 ext 24
Database Engineer                                     fax 269.349.9076
Nexcerpt, Inc.                                 http://www.nexcerpt.com           ...Nexcerpt... Extend your Expertise



В списке pgsql-sql по дате отправления:

Предыдущее
От: Troels Arvin
Дата:
Сообщение: Re: Quota query with decent performance?
Следующее
От: Yasir Malik
Дата:
Сообщение: Re: Addition and subtraction on BIT type