Oracle同程网络的几道笔试题解答(不一定对,欢迎拍砖)
Posted DB宝
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle同程网络的几道笔试题解答(不一定对,欢迎拍砖)相关的知识,希望对你有一定的参考价值。
今天小麦苗给大家分享的是同程网络的几道笔试题解答(不一定对,欢迎拍砖)。
一、 问答题(1题,30分) 下列脚本语句在语法上有哪些问题,优化后该怎么写? select substr(t.dd,1,7) as month, count(distinct t.id) from ( select fio.memberfk as id, to_date(fio.createdate) as dd, row_number() over (partition by fio.memberfk order by to_date(fio.createdate)) as num from middledata.factflyintorder fio left join dimdata.dimflyintorderflag zt on fio.orderflagfk = zt.orderflagkey where to_date(fio.createdate) >= '2016-03-01' and to_date(fio.createdate) < '2017-04-01' and zt.orderflagkey = 14 and fio.platfk = 501 group by fio.memberfk, to_date(fio.createdate) ) t where t.num = 1 order by month group by month
--默认FIO.CREATEDATE为日期类型 1.去掉表DIMDATA.DIMFLYINTORDERFLAG 2.最后的ORDER BY和GROUP BY位置调换 3.FIO.CREATEDATE BETWEEN to_date('2016-03-01','YYYY-MM-DD') AND to_date('2017-04-01','YYYY-MM-DD') 4.剩下的看执行计划吧
优化后: SELECT SUBSTR(T.DD, 1, 7) AS MONTH, COUNT(DISTINCT T.ID) FROM (SELECT FIO.MEMBERFK AS ID, TO_CHAR(FIO.CREATEDATE,'YYYY-MM-DD') AS DD, ROW_NUMBER() OVER(PARTITION BY FIO.MEMBERFK ORDER BY TO_DATE(FIO.CREATEDATE)) AS NUM FROM MIDDLEDATA.FACTFLYINTORDER FIO WHERE FIO.CREATEDATE BETWEEN to_date('2016-03-01','YYYY-MM-DD') AND to_date('2017-04-01','YYYY-MM-DD') AND FIO.PLATFK = 501 GROUP BY FIO.MEMBERFK, TO_DATE(FIO.CREATEDATE)) T WHERE T.NUM = 1 GROUP BY MONTH ORDER BY MONTH
二、 操作题(3题,70分) 机票订单表:middledata.factflyintorder 相关字段如下:
机票航司维度表:dimdata.dimflyairway 相关字段如下:
根据上面提供的信息和下面的问题,编写脚本: (1)2017年以来每月的均航段营收(提示:均航段营收=营收/航段数,sum函数;成功订单,排除测试单和无效单)
SELECT TO_CHAR(A.CREATEDATE, 'YYYYMM') AS 月份, SUM(A.TOTALTAKEOFF / LEGCOUNT) AS 均航段营收 FROM MIDDLEDATA.FACTFLYINTORDER A WHERE A.CREATEDATE >= TO_DATE('20170101', 'YYYYMMDD') AND ISVALID = 1 AND ISTEST = 0 GROUP BY TO_CHAR(A.CREATEDATE, 'YYYYMM');
(2)2017年5月各航司的总营收,输出时间,航司二字码和营收数据,并按营收倒序排列(提示:表关联,sum,order by)
SELECT A.CREATEDATE AS 输出时间, B.FLYAIRWAYCODE AS 航司二字码, SUM(A.TOTALTAKEOFF) AS 营收数据 FROM MIDDLEDATA.FACTFLYINTORDER A JOIN DIMDATA.DIMFLYAIRWAY B ON A.AIRWAYSFK = B.FLYAIRWAYKEY WHERE A.CREATEDATE = TO_DATE('201705', 'YYYYMM') GROUP BY A.AIRWAYSFK, A.CREATEDATE, B.FLYAIRWAYCODE ORDER BY TOTALTAKEOFF DESC;
(3)2017年6月1号,各航司营收最高的订单,输出航司二字码和订单号(提示:表关联,Row_number,Partition by)
SELECT 航司二字码,订单号 FROM (SELECT B.FLYAIRWAYCODE AS 航司二字码, SUM(A.TOTALTAKEOFF) AS 营收数据, A.SERIALID 订单号, ROW_NUMBER() OVER(PARTITION BY A.AIRWAYSFK, B.FLYAIRWAYCODE, A.SERIALID ORDER BY SUM(A.TOTALTAKEOFF) DESC ) RN FROM MIDDLEDATA.FACTFLYINTORDER A JOIN DIMDATA.DIMFLYAIRWAY B ON A.AIRWAYSFK = B.FLYAIRWAYKEY WHERE A.CREATEDATE = TO_DATE('20170601', 'YYYYMMDD') GROUP BY A.AIRWAYSFK, B.FLYAIRWAYCODE, A.SERIALID) WHERE RN = 1;
|
http://mp.weixin.qq.com/s/Vm5PqNcDcITkOr9cQg6T7w |
|
● 版权所有,欢迎分享本文,转载请保留出处
以上是关于Oracle同程网络的几道笔试题解答(不一定对,欢迎拍砖)的主要内容,如果未能解决你的问题,请参考以下文章