我想使用大小写时将列值分配给另一列。
在这里,我想将'CountAll'列分配给另一列。
我试图修复它,但它给了我一个错误,比如'无效的标识符'。需要你的帮助。
select cast(sysdate as timestamp(0)) SAMPLE_TIME, SQL_ID, Count(*) as "CountAll", WAIT_TIME, WAIT_CLASS,
case when wait_time!=0 then 1 end as "CPU",
case when wait_time=0 and wait_class='Scheduler' then CountAll end as "Scheduler",
case when wait_time=0 and wait_class='User I/O' then Count1 end as "User I/O",
case when wait_time=0 and wait_class='System I/O' then Count1 end as "System I/O",
case when wait_time=0 and wait_class='Concurrency' then Count1 end as "Concurrency"
FROM gv$session
答案 0 :(得分:0)
我的猜测是你想要这样的东西:
select cast(sysdate as timestamp(0)) as SAMPLE_TIME, SQL_ID,
Count(*) as CountAll,
sum(case when wait_time <> 0 then 1 else 0 end) as "CPU",
sum(case when wait_time = 0 and wait_class = 'Scheduler' then 1 else 0 end) as Scheduler,
sum(case when wait_time = 0 and wait_class = 'User I/O' then 1 else 0 end) as "User I/O",
sum(case when wait_time = 0 and wait_class = 'System I/O' then 1 else 0 end) as "System I/O",
sum(case when wait_time = 0 and wait_class = 'Concurrency' then 1 else 0 end) as "Concurrency"
FROM gv$session
GROUP BY cast(sysdate as timestamp(0)) as SAMPLE_TIME, SQL_ID;