oracle SQL语句的实现

作者&投稿:陈没态 (若有异议请与网页底部的电邮联系)
Oracle SQL语句实现~

直接执行
update 表A set New_col ='c'||substr(col,-2) 就可以了

直接从你得到的表中来看,你可以直接用flowid分组,然后其他各值求max。最后再求一个count就可以。
如果想直接写在现在的这个语句里,那么要先对Es_Attachment表,进行分组,个人感觉应该是Es_Attachment表的flowid字段,因为结果中的 es.uptime, es.filename,二者都来自于Es_Attachment表,而上面的结果中主要是es.uptime, es.filename二者的不同。
所以个人建议你可以把Es_Attachment 改为 (select flowid,max(uptime),max(filename),count(*) num from Es_Attachment) es
然后应该就是你想要的了,不过因为不知道你的 Es_Attachment的具体内容,所以这些都是猜想,具体的你可以再改改。

创建表

create table test
(id varchar2(2),
oid int,
name varchar2(1));

insert into test values ('01',1,'A');
insert into test values ('01',1,'B');
insert into test values ('01',2,'A');
insert into test values ('01',2,'C');
insert into test values ('02',1,'D');
insert into test values ('02',1,'E');
insert into test values ('03',1,'D');
insert into test values ('03',1,'E');

你说的第二步

select t.id,t.oid,replace(t.name,',','+') name
from
(select id,oid,wm_concat(name) name from test group by id,oid) t
where length(name)>1

你说的第三步

select min(s.id) id,s.oid,s.name
from
(select t.id,t.oid,replace(t.name,',','+') name
from
(select id,oid,wm_concat(name) name from test group by id,oid) t
where length(name)>1) s
group by s.oid,s.name



楼主我来帮你搞定这个问题:

1、执行的结果

sql 是:


select t.col1,
       t.col2,
       LISTAGG(t.col3,'+') WITHIN GROUP(ORDER BY t.col1, t.col2) as sumValue
  from (select t.*, t.rowid from temp_data t ORDER BY T.COL1, T.COL2, T.COL3) t
 group by t.col1, t.col2;


2、执行的结果:


sql 为:

select sumValue, count(sumValue)
  from (select t.col1,
               t.col2,
               LISTAGG(t.col3, '+') WITHIN GROUP(ORDER BY t.col1, t.col2) as sumValue
          from (select t.*, t.rowid
                  from temp_data t
                 ORDER BY T.COL1, T.COL2, T.COL3) t
         group by t.col1, t.col2) group by sumValue;



说明:模拟你的表结构

create table temp_data(
 col1 varchar2(10),
 col2 varchar2(15),
 col3 varchar2(20)
);


请自己替换表名和字段即可,PS:我很喜欢这个问题。



oracle里面rank over 和 group by,你用这个分组函数写sql,我这里没有环境,写不出来