One column to multiple columns based on constraints?

Поиск
Список
Период
Сортировка
От Davor J.
Тема One column to multiple columns based on constraints?
Дата
Msg-id hkp8lk$2ls2$1@news.hub.org
обсуждение исходный текст
Ответы R: One column to multiple columns based on constraints?  (Vincenzo Romano <vincenzo.romano@notorand.it>)
Re: One column to multiple columns based on constraints?  (John R Pierce <pierce@hogranch.com>)
Список pgsql-general
Let's say you have a table:
CREATE TABLE t (
time date,
data integer
)

Suppose you want a new table that has columns similar to the following:
"(x.time, x.data, y.time, y.data, z.time, z.data)" where x.time, y.time and
z.time columns are constrained (for example x.time >2007  AND x.time <2008,
y.time >2008 AND y.time < 2009, z.time > 2010)

How would you do this. Note that you can not use JOIN as there is no
relationship.

Currently I came up with something like this:

SELECT X.*, (SELECT Y.time, Y.data FROM t AS Y WHERE Y.time = X.time + 1),
(SELECT Z.time .) FROM t AS X WHERE  X.time >2007  AND X.time <2008

But it's somewhat awkward. I thought maybe someone has better idea's. Any
input is welcome.



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

Предыдущее
От: Ivan Sergio Borgonovo
Дата:
Сообщение: turning a tsvector without position in a weighted tsvector
Следующее
От: "Davor J."
Дата:
Сообщение: Creating subsets on timestamp with modulo, date_trunc and ?suggestions?