04.有深度的SQL整理

查询各部门中工资比本部门平均工资高的员工的员工号, 姓名和工资
SELECT A.deptno,A.ename,A.sal FROM EMP A,(select deptno,AVG(SAL) AS "平均工资" from emp group by deptno) B

WHERE A.DEPTNO=B.deptno AND SAL>b.平均工资
image.png

查询

SELECT /*+parallel(8)*/AC02.AAA027,
             AC02.AAB034,
             PRM_ISSUE,
             ab01.aab019,
             AC01.AAC084,
             AC01.AAC004,
             AC02.AAC031,
             AC01.AAC028,
             AC01.AAC161,
             COUNT(DISTINCT AC02.AAC001)
        FROM AC02, v_ab01 AB01, AC01, AB02
       WHERE AC01.AAC001 = AC02.AAC001
         AND AB01.AAB001 = AC02.AAB001
         AND AC02.AAB001 = AB02.AAB001
         AND AC02.AAE140 = AB02.AAE140
         AND ac02.aae140 = '110'
         and ac02.aac031 <> '3'
         and ac01.aac084 = '0'
         AND AC01.AAC032 = '1'
         AND NOT EXISTS(SELECT 1
                              FROM AC60
                             WHERE AAC001 = AC01.AAC001
                               AND SUBSTR(AAC121, 1, 1) IN ('2', '3')
                               AND AAE116 IN ('1', '2'))
         and exists(select 1 from sicp4_collectioncenter.V_AC43ACI8 
                     where aac001=ac01.aac001 and aae140='110')
         AND SUBSTR(TO_CHAR(AC02.AAC049),0,6) <= 统计年月
         AND NOT EXISTS(SELECT 1 FROM tjbtq WHERE AAC001=AC01.AAC001)
       GROUP BY AC02.AAA027,
                AC02.AAB034,
                ab01.aab019,
                AC02.AAE140,
                AC01.AAC084,
                AC01.AAC004,
                AC02.AAC031,
                AC01.AAC028,
                AC01.AAC161;

UPDATE A表
   SET 字段 =
       (SELECT 字段B FROM B表 WHERE AAC001 = A表.AAC001)
 WHERE EXISTS (SELECT 1 FROM B表 WHERE AAC001 = A表.AAC001);
 
 


 update hjian_2 set HJIAN=(SELECT DISTINCT HJIAN FROM hjian WHERE AAC001 = hjian_2.AAC001)
 
 WHERE EXISTS (SELECT 1 FROM hjian WHERE AAC001 = hjian_2.AAC001);

SELECT ic91.*,
                                case
                                  when prm_aab301 like '21%' then
                                   aae269
                                  else
                                   nvl(aae382, 0) - lag(aae382, 1, 0)
                                   over(order by aae001, aae041) -
                                   nvl(aae381, 0)
                                end lx,
                                case
                                  when prm_aab301 like '21%' then
                                   aae269
                                  else
                                   nvl(aae273, 0) - lag(aae273, 1, 0)
                                   over(order by aae001, aae041) -
                                   nvl(aae264, 0)
                                end grlx
                           FROM IC91
                          WHERE AAC001 = PRM_AAC001
                            AND AAZ341 = PRM_AAZ341
                            AND aae382 > 0
                          ORDER BY AAE001, AAE041
select ename,sal from
   (
     select ename,sal,rownum r from  (select ename,sal from emp order by sal desc)
   )
  where r<=3
select a.aab001,(select aab004 from sicp4_basicinfocenter.abp1 where aab001 = a.aab001) 单位名称,aae002,aae003,aab031,aae020,aae023,c.bab082,a.aab034 from sicp4_collectioncenter.ab07 a,lnsi_commonbusiemp.aba1 c WHERE a.aab001 = c.aab001 and
AAE003 BETWEEN 202002 AND 202012 AND AAE002<202103 AND AAA115='20' and aae491 = '1' and aae132 =  '1' and bab082 in ('2','3','4') and aae020 <> '0';
SELECT P.AAB001 单位编号 , P.aab004 AS 单位名称,P. AAE004 AS 联系人, P.AAE005 AS 联系电话, G.MS AS 最后缴纳时间,G.aab119 AS 缴纳人数,
decode(P.AAB034,'210200000000','大连市',
                   '210202000000','中山区',
                   '210203000000','西岗区',
                   '210204000000','沙河口区',
                   '210211000000','甘井子区',
                   '210212000000','旅顺口区',
                   '210213000000','金州区',
                   '210214000000','普兰店区',
                   '210224000000','长海县',
                   '210240000000','开发区',
                   '210241000000','保税区',
                   '210242000000','长兴岛临港工业区',
                   '210243000000','花园口经济区',
                   '210244000000','金普新区',
                   '210281000000','瓦房店市',
                   '210282000000','普兰店市',
                   '210283000000','庄河市',
                   '210299000000','大连市市本级',
                   '210201000000','大连市本级') AS 经办机构
  FROM SICP4_BASICINFOCENTER.AB01 P,
       (SELECT E.AAB119, F.ms,F.aab001
          FROM SICP4_COLLECTIONCENTER.AB07 E,
               (SELECT AAB001, MAX(AAE003) AS MS
                  FROM SICP4_COLLECTIONCENTER.AB07
                 WHERE AAB001 IN
                       (SELECT AAB001
                          FROM SICP4_BASICINFOCENTER.AB01
                         WHERE AAB001 IN (2102071705969))
                 GROUP BY AAB001) F
         WHERE E.AAB001 = F.AAB001
           AND E.AAE003 = F.MS) G WHERE P.AAB001 = G.AAB001;
       
select aab001,aab119,aae003 from sicp4_collectioncenter.ab07 a  where  aab001 in(2102000192627,
2102000192645,
2102000193106,
2102000191305,
2102000000000,
2102000190402,
2102000190720,
2102000191602,
2102000190401,
2102000192692,
2102000192706,
2102000192628,
2102000192802,
2102000192900,
2102000191405,
2102000192726) and aae491 = '1'
and aae003 = (select max(aae003) from sicp4_collectioncenter.ab07 where aab001 = a.aab001)
WITH TEMP_A AS
 (SELECT AAB001, MAX(AAE003) AS AAE003
    FROM SICP4_COLLECTIONCENTER.AB07
   WHERE AAB001 IN (2102000192627,
                    2102000192645,
                    2102000193106,
                    2102000191305,
                    2102000000000,
                    2102000190402,
                    2102000190720,
                    2102000191602,
                    2102000190401,
                    2102000192692,
                    2102000192706,
                    2102000192628,
                    2102000192802,
                    2102000192900,
                    2102000191405,
                    2102000192726)
   GROUP BY AAB001)
SELECT A. AAB001, A.AAE003, SUM(AAB119) RS
  FROM TEMP_A A, SICP4_COLLECTIONCENTER.AB07 B
 WHERE A.AAB001 = B.AAB001 AND A.AAE003 = B.AAE003
 GROUP BY A.AAB001, A.AAE003;
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,686评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,668评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,160评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,736评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,847评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,043评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,129评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,872评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,318评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,645评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,777评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,470评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,126评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,861评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,095评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,589评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,687评论 2 351

推荐阅读更多精彩内容