当前位置:首页 » 编程语言 » oraclesql行变列
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

oraclesql行变列

发布时间: 2022-11-22 19:19:20

Ⅰ Oracle sql如何实现“可判断的行转列”的方法

如果确定只有最多三个项列那么可以这样
select 组号,单位,项一 项目号
,项一名 项目名
from tab where 项一 is not null
union all
select 组号,单位,项二,项二名 from tab where 项二 is not null
union all
select 组号,单位,项三,项三名 from tab where 项三 is not null
;
如采纳加分

Ⅱ oracle行转列写法,麻烦大家帮忙写个sql,谢谢

可以用wm_concat函数先把数据变成行显示,然后再通过截取来显示具体的月份,wm_concat转换如下

selectcompay_namecn,wm_concat(income)ic

from(selectcompay_name,sum(income)income,substr(time,1,6)time

fromincome

---wheretime>=start_monthandtime<=end_month

groupbycompay_name,substr(time,1,6)

orderbycompay_name,substr(time,1,6))

groupbycompay_name;

Ⅲ ORAClE sql如何实现行转列

如果“站名”、“条码”、“时间”都是一样的话,可以这么写:

with
t_temp as (select row_number() over (partition by station_name order by param_name asc) id, t.* from t),
t_temp1 as (select * from t_temp where id = 1),
t_temp2 as (select * from t_temp where id = 2),
t_temp3 as (select * from t_temp where id = 3)
select '站名' col1, '条码' col2, t_temp1.参数名 col3, t_temp2.参数名 col4, t_temp3.参数名 col5, '时间' col6
from t_temp1, t_temp2, t_temp3
where t_temp1.站名 = t_temp2.站名
and t_temp2.站名 = t_temp3.站名
union all
select t_temp1.站名, t_temp1.条码, to_char(t_temp1.数值), to_char(t_temp2.数值), to_char(t_temp3.数值), to_char(t_temp1.时间)
from t_temp1, t_temp2, t_temp3
where t_temp1.站名 = t_temp2.站名
and t_temp2.站名 = t_temp3.站名

Ⅳ oracle 如何将 行转换为列 (具体如下,求sql)

WITHAAS(SELECTID_F,LINE_F,STAGE_F,UNITSTAGE_F,CAST(CHILDSTAGE_FASVARCHAR(100))ASCHILDSTAGE_F,PARENTID_FFROM表名WHEREPARENTID_FISNULL
UNIONALL
SELECT表名.ID_F,表名.LINE_F,表名.STAGE_F,表名.UNITSTAGE_F,CAST(A.CHILDSTAGE_F+表名.CHILDSTAGE_FASVARCHAR(100))ASCHILDSTAGE_F,表名.PARENTID_F
FROM表名JOINAON表名.PARENTID_F=A.ID_F)
SELECTLINE_F,STAGE_F,UNITSTAGE_F,CHILDSTAGE_F
FROMA
WHEREPARENTID_FISNOTNULL