`

oracle数据处理sql

阅读更多
--插入语句之不同表中相同字段的快捷插入
insert into z_nm_site_ent(site_ent_id,ent_name)  select site_ent_id,shop_name from z_nm_test

--这部分数据直接插入到主体和店铺中,但是需要关联上    且不在主体表中存在的
select *
  from Z_NM_SHOP_ALL a
where exists (select 1
          from (select count(1), shop_name
                  from Z_NM_SHOP_ALL
                 group by shop_name
                having(count(1) = 1))  b where a.shop_name=b.shop_name) and zc_name is null
               
-- 这部分数据是名称有重复的,所以主体只能插入一条  (查询name重复的数据条数)
select count(1),shop_name from  Z_NM_SHOP_ALL where   zc_name is null group by shop_name having(count(1)>1)
     --  需要把这些名称对应的店铺关联上
    
--- zc_name 不为空的
     select count(1),zc_name from  Z_NM_SHOP_ALL  where zc_name is not null   group by zc_name
      -- 同样把主体ID关联过来


--替换时间字段中的空字符
update z_nm_evment_all set EV_TIME=replace(EV_TIME,' ','')
where length(EV_TIME)>10 and EV_TIME like '% %' and length(EV_TIME)<12


--oracle判断
select case
when
length(EV_TIME)>10
then
to_date(EV_TIME,'yyyy-MM-dd hh24:mi:ss')




--拼接,没有日期的数据默认为某月1日
update  z_nm_evment_all set EV_TIME=EV_TIME || '/1'  where length(EV_TIME)=6


--查询指定字符串 在该字段中出现的次数
SELECT LENGTHB(TRANSLATE(EV_TIME,'/'|| EV_TIME,'/')) FROM z_nm_evment_all;

update z_nm_evment_all set  EV_TIME=EV_TIME || '/1' where LENGTHB(TRANSLATE(EV_TIME,'/'|| EV_TIME,'/'))!=2;


--评论插入sql

insert into z_nm_evaluation(EV_ID,SHOP_ID,EV_TIME,EV_USER,EV_CONTENT,IS_BAD,GOOD_ID)
select EV_ID,SHOP_ID,
case when
length(EV_TIME)>10
then
to_date(EV_TIME,'yyyy-MM-dd hh24:mi:ss')
else
to_date(EV_TIME,'yyyy-MM-dd')
end
,EV_USER,EV_CONTENT,IS_BAD,GOOD_ID from z_nm_evment_all


---两表关联 批量修改sql
update z_nm_site_ent a set a.ssgss=(select b.ssgss from z_nm_site_ent_info b where b.ent_name=a.ent_name and rownum =1)
where a.ent_name in (select b.ent_name from  z_nm_site_ent_info b)


修改同一张表中的重复数据, 把字段不为空的那一条数据字段 更新到字段为空的另一条数据字段中, z_nm_shop_id为重复数据的标识中间表(select shop_id from nm_shop group by shop_id having(count(1)>1) 例如重复数据的shop_id相同)

--修改店铺重复的数据字段,然后保留一条

update nm_shop w
   set w.ev_num =
       (select ev_num
          from nm_shop b
         where exists
         (select 1 from z_nm_shop_id h where h.shop_id = b.shop_id)
           and ev_num is not null
           and rownum = 1)
where w.ev_num is null
and exists (select 1 from z_nm_shop_id n where n.shop_id=w.shop_id)

---批量修改操作,并且只执行一条

update a_a_nm_shop_45 a  set a.type_code=
(select b.shop_sub_type from nm_shop_type b where a.shop_id=b.shop_id and rownum=1)






--删除重复
delete   from z_reg_bus_ent a
where rowid!=(select   max(rowid)   from z_reg_bus_ent b where a.ent_name=b.ent_name)

--查询时间段数据
select * from  nm_evaluation where to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-04%'




--插入评论数据
insert into nm_evaluation
select ev_id, shop_id,to_date(ev_time,'yyyy-mm-dd'),ev_user,to_number(ev_num),ev_content,is_bad,add_time,ev_title,good_id from a_a_nm_evment_45



--统计评论量
select a.shop_id as 店铺编号,a.shop_name as 店铺名称,
a.platform_code as 平台编号,a.shop_address as 店铺地址 ,a.shop_url as url,
a.ev_num as 总评数量,a.bad_ev_num as 总差评数,
(select count(1) from nm_evaluation b where b.shop_id=a.shop_id and to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-01%') as 啊1月总评论数,
(select count(1) from nm_evaluation b where b.shop_id=a.shop_id and b.is_bad='1' and to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-01%') as 啊1月差评论数,
(select count(1) from nm_evaluation b where b.shop_id=a.shop_id and to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-02%') as 啊2月总评论数,
(select count(1) from nm_evaluation b where b.shop_id=a.shop_id and b.is_bad='1' and to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-02%') as 啊2月差评论数,
(select count(1) from nm_evaluation b where b.shop_id=a.shop_id and to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-03%') as 啊3月总评论数,
(select count(1) from nm_evaluation b where b.shop_id=a.shop_id and b.is_bad='1' and to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-03%') as 啊3月差评论数,
(select count(1) from nm_evaluation b where b.shop_id=a.shop_id and (to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-04%' or to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-05%' )) as 啊45月总评论数,
(select count(1) from nm_evaluation b where b.shop_id=a.shop_id and b.is_bad='1' and (to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-04%' or to_char(to_date(ev_time),'yyyy-mm-dd')  like '%2017-05%' )) as 啊45月差评论数

from aa_nm_shop_1_5 a

分享到:
评论

相关推荐

    oracle 数据处理sql语句源码

    oracle 数据处理sql语句源码 相当不错的一个监测项目的数据处理语句

    Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(一)

    Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(一) http://download.csdn.net/source/3268267 Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(二) ...

    Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(二)

     本书是专门为oracle应用开发人员提供的sql和pl/sql编程指南。通过学习本书,读者不仅可以掌握oracle常用工具oracle universal installer、net comfiguration assistant、sql developer、sql*plus的作用及使用方法...

    oracle批量执行sql

    // ※只会执行sql文 不会自动删除表内数据 // oracleStup.bat // 命令行 用户名/密码 @库名 不需要修改 sqlplus C3/AISIN@C3 @sqlFile.sql &gt; execute.log // sqlFile.sql // @@需要处理的sql文路径 @@D:/20150922...

    Oracle 11g SQL和PL SQL从入门到精通〖送源代码〗

    本书是专门为Oracle应用开发人员提供的SQL和PL/SQL编程指南。通过学习本书,读者不仅可以掌握Oracle常用工具Oracle Universal Installer、Net Comfiguration Assistant、SQL Developer、SQL*Plus的作用及使用方法,...

    Oracle PL SQL程序设计 上 第五版(代码示例)

    《oracle pl/sql程序设计(第5版)》基于oracle数据库11g,从pl/sql编程、pl/sql程序结构、pl/sql程序数据、pl/sql中的sql、pl/sql应用构建、高级pl/sql主题6个方面详细系统地讨论了pl/sql以及如何有效地使用它。...

    Oracle PL/SQL语言初级教程

    PL/SQL是Oracle对标准数据库语言的扩展,Oracle公司已经将PL/SQL整合到Oracle 服务器和...通过本教程的学习,您将初步掌握PL/SQL语言,能够利用PL/SQL语言完成建表、查询、添加、删除数据以及事务处理语句的基本用法。

    高性能动态SQL Oracle数据安全 Oracle 数据库的聚簇技术 等等

    保持Oracle数据优良性能 12 提高Oracle数据库查询统计速度 14 Oracle中巧取指定记录 14 Oracle数据安全 15 Oracle字段上建立并使用索引 29 用Windows脚本宿主自动化Oracle工具 31 进程结构和内存结构 32 Oracle监控...

    Oracle 11g SQL和PL SQL从入门到精通.part1

     本书是专门为oracle应用开发人员提供的sql和pl/sql编程指南。通过学习本书,读者不仅可以掌握oracle常用工具oracle universal installer、net comfiguration assistant、sql developer、sql*plus的作用及使用方法...

    Oracle数据库维护常用SQL语句集合

    Oracle数据库维护常用SQL语句集合,详细介绍了数据库维护的操作语句

    ORACLE数据库中SQL优化解析.pdf

    ORACLE数据库中SQL优化解析.pdf

    Oracle PL_SQL语言初级教程

    PL/SQL 是一种高性能的基于事务处理的语言,能运行在任何 ORACLE 环境中,支持所有数据处理命令。 通过使用 PL/SQL 程序单元处理 SQL 的数据定义和数据控制元素。 • Oracle PL/SQL语言基础(1) • Oracle PL/SQL语言...

    精通Oracle_PL/SQL

    全书涵盖了 PL/SQL提供的大量功能,包括高效数据处理、安全、触发器、DBA包以及高效的调试技术等。此外,书中含有丰富的示例,并提供了大量提示和技巧。《精通Oracle PL/SQL》结构清晰,示例丰富,实践性强,适用于 ...

    Oracle数据库、SQL

    三、 SQL语句的处理过程 7 3.1 SQL语句处理过程 7 3.2处理一条select语句 7 四、 where子句 8 4.1 where子句后面可以跟什么 8 4.2语法和执行顺序 8 4.3字符串是大小写敏感的,在比较时严格区分大小写 8 4.4 where...

    Oracle PL SQL

    走进Oracle、认识PL/SQL、数据表的基本操作、表中数据的基本操作、数据的基本查询、查询中函数的使用、数据表的高级查询、索引及视图的使用、数据类型、流程控制、游标、存储过程和函数、触发器、异常处理、事务和锁...

    基于ORACLE数据库的SQL优化研究.pdf

    基于ORACLE数据库的SQL优化研究.pdf

    Oracle 11g SQL和PL SQL从入门到精通part2 pdf格式电子书 下载(二)

    Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(一) http://download.csdn.net/source/3268267 Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(二) ...

    精通Oracle PL/SQL 图灵

    与市面上许多pl/sql图书只是纸上谈兵、局限于语法和功能本身不同,本书从实战出发,讲述如何正确、充分地运用语言特性,除了pl/sql的基本功能之外,也包括数据的高效处理、安全、触发器、高效的调试技术等。...

    基于Oracle数据库的SQL优化原则和方法.pdf

    基于Oracle数据库的SQL优化原则和方法.pdf

    Oracle数据库SQL基本应用与介绍

    Oracle数据库内部的数据操作可以通过sql语句执行处理,sql与C、Basic等语言不通,数据的访问方法和操作顺序不用正确指定,是要告诉数据库引擎要做什么就可以了。Oracle不仅可以通过基本的sql进行简单的数据操作,还...

Global site tag (gtag.js) - Google Analytics