我有一个网格元素,需要在一列中输入值
Key_id event1 name1 date1 price1 event2 name2 date2 price2
234 Marriage Sasha 09-DEC 4300 Birthday Kate 10-DEC 3000
我的SQL查询输出将返回行
中列出的数据Key_id event Name date price
234 Marriage Sasha 09-DEC 4300
234 Birthday Kate 10-DEC 3000
所以我需要根据key_id将行列表转换或转换为列。这些值不是固定的,而是根据用户选择的时间段动态显示。
我在这个论坛中遇到过类似的问题,但我想知道使用任何Java API或SQL查询是否可以实现同样的目的。
请告诉我如何实现这个目标。
由于
答案 0 :(得分:0)
根据您的问题,我猜您想将水平轴(列)转换为垂直轴。
使用类似:
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
这对你有帮助吗?如果是,请确认。如果没有,请留言。