Creative use of CASE in a GROUP BY clause

Поиск
Список
Период
Сортировка
От Dorian Taylor
Тема Creative use of CASE in a GROUP BY clause
Дата
Msg-id F4zhQoKH6tw5u3A64Bo00002071@hotmail.com
обсуждение исходный текст
Ответы Re: Creative use of CASE in a GROUP BY clause  (Masaru Sugawara <rk73@sea.plala.or.jp>)
Список pgsql-sql
Greets,

I'm trying to figure out how to craft a query that I can embed into a piece
of code that can be passed a bind value in order to dictate how it should
behave on GROUP BY, sparing me from having to write separate queries for N
functions and/or columns I may want to group my query by.

e.g. SELECT COUNT(foo) FROM bar GROUP BY CASE (? IS NOT NULL) THEN thiscol
ELSE thatcol END

If thiscol and thatcol aren't the same type, the CASE bombs out. I suppose
ultimately it would be a matter of reducing each column definition in the
CASE to a boolean expression, but I'm not sure what that would syntactically
look like, as simply declaring a column in GROUP BY is obviously shorthand
for something.

Thanks

Dorian

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com



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

Предыдущее
От: Rudi Starcevic
Дата:
Сообщение: Re: Boolean test
Следующее
От: Masaru Sugawara
Дата:
Сообщение: Re: Creative use of CASE in a GROUP BY clause