admin管理员组文章数量:1208153
Here is my code:
table as (
SELECT
day,
district,
uc,
team_member,
role_type,
MAX(CASE WHEN text = 'AFP Cases Notified' THEN response_value END) AS AFP_Cases_Notified
from finalset
where day=1
GROUP BY day, district, uc, team_member, role_type
)
SELECT
label,
value
FROM
table,
LATERAL (
VALUES
('day', "day"::text),
('district', "district"::text),
('uc', "uc"::text),
('team_member', "team_member"::text),
('role_type', "role_type"::text),
('afp_cases_notified', afp_cases_notified)
) AS t(label, value)
This has output like:
whereas what I want is output like:
i.e. the fixed row labels should only appear once in the rows. This can be done with a single transpose in excel, but I have tried many methods without success in postgres.
本文标签: postgresqlTransposing columns into rowswith fixed row labelsStack Overflow
版权声明:本文标题:postgresql - Transposing columns into rows, with fixed row labels - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738713675a2108345.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论