12
返回列表 发新帖
楼主: bingfengguan

[PL/SQL] 面试题如何入手,求解 thx

[复制链接]
论坛徽章:
6
秀才
日期:2015-07-14 09:44:30秀才
日期:2015-07-28 09:11:43巨蟹座
日期:2015-12-22 23:17:51白羊座
日期:2016-01-17 22:36:152016猴年福章
日期:2016-02-18 09:31:30奥运会纪念徽章:篮球
日期:2016-09-08 22:13:34
11#
 楼主| 发表于 2016-9-29 21:35 | 只看该作者
bell6248 发表于 2016-9-29 14:13
如下:

SQL> with t as

再次感谢,
case when prior salary < salary then 1 else 0 end flag 佩服,之前用递归卡死在这了

使用道具 举报

回复
论坛徽章:
6
秀才
日期:2015-07-14 09:44:30秀才
日期:2015-07-28 09:11:43巨蟹座
日期:2015-12-22 23:17:51白羊座
日期:2016-01-17 22:36:152016猴年福章
日期:2016-02-18 09:31:30奥运会纪念徽章:篮球
日期:2016-09-08 22:13:34
12#
 楼主| 发表于 2016-9-29 21:44 | 只看该作者
kelis2004 发表于 2016-9-29 15:04
SELECT * FROM tmp  t1
WHERE t1.salary >ALL (SELECT salary FROM tmp t2 WHERE t1.relation =t2.id)
AN ...

再次感谢,之前怎么也想不到如何建立联系,原来是可以这样创造的,
真的要脑补了。。

使用道具 举报

回复
论坛徽章:
1
优秀写手
日期:2013-12-18 09:29:13
13#
发表于 2016-9-30 10:37 | 只看该作者
select id
  from employee t
where t.relation is not null
   and exists (select 1
          from employee t2
         where t2.id = t.relation
           and t2.salary < t.salary)

使用道具 举报

回复
论坛徽章:
28
2013年新春福章
日期:2013-02-25 11:02:12马上有车
日期:2014-08-13 09:14:10itpub13周年纪念徽章
日期:2014-10-08 15:22:13itpub13周年纪念徽章
日期:2014-10-08 15:22:13itpub13周年纪念徽章
日期:2014-10-08 15:22:13itpub13周年纪念徽章
日期:2014-10-08 15:22:13itpub13周年纪念徽章
日期:2014-10-08 15:22:13itpub13周年纪念徽章
日期:2014-10-08 15:22:13itpub13周年纪念徽章
日期:2014-10-08 15:22:13itpub13周年纪念徽章
日期:2014-10-08 15:22:13
14#
发表于 2016-10-6 10:35 | 只看该作者
select * from t_emp a
  where  exists (select * from t_emp b where a.salary>b.salary  and b.relation is null)

使用道具 举报

回复
论坛徽章:
6
2014年新春福章
日期:2014-02-18 16:49:31马上有钱
日期:2014-02-18 16:49:31优秀写手
日期:2014-02-21 06:00:13马上有车
日期:2014-10-09 10:14:53技术图书徽章
日期:2017-07-12 17:18:46妮可·罗宾
日期:2017-08-10 12:13:56
15#
发表于 2016-10-7 09:00 | 只看该作者

with tb as
(select 3 id, null relation, '张三' name, 800 sal
    from dual
  union all
  select 1 id, 3 relation, 'jack', 700 sal
    from dual
  union all
  select 4 id, null relation, '李四', 800 sal
    from dual
  union all
  select 2 id, 4 relation, ' shisi', 900 sal
    from dual)
select id,name,relation,sal from (
select t1.id,
       t1.name,
       t1.relation,
       t1.sal,
       case
         when exists (select 1
                 from tb
                where tb.id = t1.relation
                start with relation is null
               connect by prior id = relation
               ) then lag(t1.sal)over(order by rownum) end new_sal
  from tb t1)
  where sal>new_sal
c:\users\administrator\桌面\20161007

使用道具 举报

回复
论坛徽章:
6
2014年新春福章
日期:2014-02-18 16:49:31马上有钱
日期:2014-02-18 16:49:31优秀写手
日期:2014-02-21 06:00:13马上有车
日期:2014-10-09 10:14:53技术图书徽章
日期:2017-07-12 17:18:46妮可·罗宾
日期:2017-08-10 12:13:56
16#
发表于 2016-10-7 09:03 | 只看该作者

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表