Answer the question
In order to leave comments, you need to log in
postgres crosstab?
I want to create a show.
approximately such a base,
that is, analiz_create has several records in analiz_data
and you need to "flip" the selection to get
it, you need to select all records from the analiz_data table grouped by analiz_create id
UPD
something tells me that I need to use crosstab but here
select * from crosstab('SELECT
t1.value,
t2.name
FROM
analiz_data t1,
element t2
WHERE
t1.elem_id = t2.id ')
as (value text, name text);
ERROR: invalid source data SQL statement DETAIL: The provided SQL must return 3 columns: rowid, category, and values.
Answer the question
In order to leave comments, you need to log in
select * from
crosstab('SELECT
t1.analiz_id,
t1.elem_id,
t1.value
FROM
a_analiz_data t1
WHERE
t1.analiz_id =36
', //analiz_id - общий ид,
//elem_id - имя элемента
//value - отображаемое значение
' SELECT
elem_id //elem_id - видимо нужен для связи двух таблиц
FROM
a_analiz_data t1
WHERE
t1.analiz_id = 36')
as (rowid int, att1 text, att2 text, att3 text, att4 text, att5 text, att6 text, att7 text);
SELECT
t1.value,
t1.elem_id
FROM
a_analiz_data t1
WHERE
t1.analiz_id =36
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question