[英]Transposing rows to a single column
I have a grid element which requires input values in a single column 我有一个网格元素,需要在单个列中输入值
Key_id event1 name1 date1 price1 event2 name2 date2 price2
234 Marriage Sasha 09-DEC 4300 Birthday Kate 10-DEC 3000
My SQL query output will return data listed in rows 我的SQL查询输出将返回行中列出的数据
Key_id event Name date price
234 Marriage Sasha 09-DEC 4300
234 Birthday Kate 10-DEC 3000
So i need to transpose or convert the list of rows to columns based on key_id.The values are not fixed and will be dynamic based on the time period selected by the user. 所以我需要根据key_id将行列表转置或转换为列。这些值不是固定的,并且会根据用户选择的时间段是动态的。
I have gone through similar questions in this forum , But i would like to know whether the same thing can be achieved using any Java API or SQL queries. 我在这个论坛上曾经历过类似的问题,但是我想知道是否可以使用任何Java API或SQL查询来实现相同的目的。
Kindly enlighten me on how to achieve this .. 请启发我如何实现这一目标..
Thanks 谢谢
From your question I guess you want to transpose the horizontal axis (columns) into vertical. 根据您的问题,我想您想将水平轴(列)转置为垂直轴。
Use something like: 使用类似:
select t.key_id
, t.event1 event
, t.name1 name
, t.date1 date_event
, t.price1 price
from table t
union all
select t.key_id
, t.event2 event
, t.name2
, t.date2
, t.price2
from table t
Did this help you? 这对您有帮助吗? If so, please confirm.
如果是这样,请确认。 If not, please leave a note.
如果没有,请留下笔记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.