oracel查询时的一个小问题,请教一下大家

时光是琥珀 2015-02-12 05:54:37
问题是这样的,一张单可能由一个部门去完成,也有可能由多个部门去完成,但是在查询的时候,查询表里面的实施部门(去完成的部门)我用的是多个字段分开存储的(实施部门1,实施部门2),那查询的时候该怎么查啊,现在能查到的是实施部门1,那查实施部门2的时候,就只能查它作为实施部门1状态的单,作为实施部门2时候的单就查不到了,现在我想能查到关于这个实施部门2的所有单,无论他作为实施部门1还是实施部门2,这该如何做啊?请教大家
...全文
260 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
也可以这样写: where 实施部门1||实施部门2||实施部门。。。 is not null
IceIsabel 2015-02-13
  • 打赏
  • 举报
回复
引用 4 楼 u012393070 的回复:
引用 3 楼 IceIsabel 的回复:
当然如果字段不多的话,可以用or
or的方法我尝试过了,虽然查的出来,但是会有多条数据,因为不仅仅只有2个实施部门
什么意思?我说的or方法是实施部门1 =‘要查的部门名称’or 实施部门2 =‘要查的部门名称’or ...这样的,这样就是查出来你要查的部门的单
IceIsabel 2015-02-13
  • 打赏
  • 举报
回复
引用 7 楼 u012393070 的回复:
引用 5 楼 IceIsabel 的回复:
[quote=引用 4 楼 u012393070 的回复:] [quote=引用 3 楼 IceIsabel 的回复:] 当然如果字段不多的话,可以用or
or的方法我尝试过了,虽然查的出来,但是会有多条数据,因为不仅仅只有2个实施部门
什么意思?我说的or方法是实施部门1 =‘要查的部门名称’or 实施部门2 =‘要查的部门名称’or ...这样的,这样就是查出来你要查的部门的单[/quote] 这样的确查到了啊,但是有重复的数据啊,,在楼下我把oracel语句贴出来吧[/quote] 所有都重复吗?如果都重复就distinct一下。 另外还要看一下为什么重复,具体看下表关联是否缺少条件
时光是琥珀 2015-02-13
  • 打赏
  • 举报
回复
select t.newid id,
       t.title,
       t.name,
       t.contact,
       t.extensionnum,
       t.telephone,
       t.enforcementdepartments1,
       t.contact1,
       t.extensionnum1,
       t.telephone1,
       t.enforcementdepartments2,
       t.contact2,
       t.extensionnum2,
       t.telephone2,
       t.enforcementdepartments3,
       t.contact3,
       t.extensionnum3,
       t.telephone3,
       t.enforcementdepartments4,
       t.contact4,
       t.extensionnum4,
       t.telephone4,
       t.enforcementdepartments5,
       t.contact5,
       t.extensionnum5,
       t.telephone5,
       t.range,
       code,
       usernum,
       accord,
       t.newtype,
       description,
       starttime,
       endtime,
       newcontent,
       subtitles,
       bulletin,
       ivr,
       notes,
       state,
       creatcard,
       creattime,
       actualtime,
       decode(mark, 1, '提前', 2, '延时', 3, '警告', 0, '正常') mark,
       card,
       operationtime,
       stime,
       etime,
       newcontentb,
       feedbackcard,
       reviewer,
       feedbacktime,
       decode(newtypeb, 1, '审核', 2, '反馈', 3, '调整') newtypeb,
       closecard,
       closereason
  from (select a.*,
               b.*,
               c.*,
               a.id newid,
               a.type newtype,
               a.content newcontent,
               b.content newcontentb,
               b.type newtypeb,
               row_number() over(partition by a.id order by a.creattime desc) r1
          from network_checkin a, network_adjustlog b, network_department c
         where a.id = b.id(+)
           and a.enforcementdepartments = c.deptid) t
 where r1 = 1
   and name = '技术部'
    or enforcementdepartments1 = '9'
    or enforcementdepartments2 = '9'
    or enforcementdepartments3 = '9'
    or enforcementdepartments4 = '9'
    or enforcementdepartments5 = '9'
 order by t.creattime desc
时光是琥珀 2015-02-13
  • 打赏
  • 举报
回复
引用 5 楼 IceIsabel 的回复:
引用 4 楼 u012393070 的回复:
[quote=引用 3 楼 IceIsabel 的回复:]
当然如果字段不多的话,可以用or
or的方法我尝试过了,虽然查的出来,但是会有多条数据,因为不仅仅只有2个实施部门

什么意思?我说的or方法是实施部门1 =‘要查的部门名称’or 实施部门2 =‘要查的部门名称’or ...这样的,这样就是查出来你要查的部门的单[/quote] 这样的确查到了啊,但是有重复的数据啊,,在楼下我把oracel语句贴出来吧
时光是琥珀 2015-02-12
  • 打赏
  • 举报
回复
引用 3 楼 IceIsabel 的回复:
当然如果字段不多的话,可以用or
or的方法我尝试过了,虽然查的出来,但是会有多条数据,因为不仅仅只有2个实施部门
IceIsabel 2015-02-12
  • 打赏
  • 举报
回复
当然如果字段不多的话,可以用or
IceIsabel 2015-02-12
  • 打赏
  • 举报
回复
http://bbs.csdn.net/topics/390979522 看一下这个帖子,类似的问题,可以参考一下
  • 打赏
  • 举报
回复
where 实施部门1 is not null or 实施部门2 is not null

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧