首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

关于union all的 有关问题 ,求教

2011-12-22 
关于union all的 问题 ,求教。Selectt_4.*From(Selectt_2.*FromExtend_Daily_Reportt_2Wheret_2.Dr_User_Id

关于union all的 问题 ,求教。
Select   t_4.*
From   (Select   t_2.*
  From   Extend_Daily_Report   t_2
  Where   t_2.Dr_User_Id   =   '1920 '
  Union   All
  Select   t_0.*
  From   Extend_Daily_Report   t_0,   Extend_Daily_Task   t_1
  Where   t_0.Dr_Id   =   t_1.Dr_Id   And   t_1.Dt_Pm_Id   =   '1920 '   And   (t_0.Dr_Status   =   '1 '   Or   t_0.Dr_Status   =   '2 ')   And
  t_0.Dr_Dept_Id   <>   '2008 '  
  Union   All
  Select   t_3.*
  From   Extend_Daily_Report   t_3
  Where   (t_3.Dr_Status   =   '1 '   Or   t_3.Dr_Status   =   '2 ')   And   t_3.Dr_Dept_Id   =   '2008 '   And   t_3.dr_user_id <> '1920 ')   t_4

工作中写了一个这样得   sql   实现了我的需求,感觉用union   不妥。由于小弟sql很差求教各位给出一个不用union   all   的   sql   来实现这个功能。多谢

[解决办法]
select t.* from Extend_Daily_Report t, Extend_Daily_Task t_1
where t.Dr_Id = t_1.Dr_Id
and dr_User_id= '1920 '
And (t.Dr_Dept_Id <> '2008 ' and (t.Dr_Status = '1 ' Or t.Dr_Status = '2 ') )
and ((t.Dr_Status = '1 ' Or t.Dr_Status = '2 ') And t.Dr_Dept_Id = '2008 ' And t.dr_user_id <> '1920 ')
[解决办法]
Select t_0.*
From Extend_Daily_Report t_0, Extend_Daily_Task t_1
Where
t_0.Dr_User_Id = '1920 ' or
((t_0.Dr_Status = '1 ' Or t_0.Dr_Status = '2 ') And t_0.Dr_Dept_Id = '2008 ' And t_0.dr_user_id <> '1920 ') or
(t_0.Dr_Id = t_1.Dr_Id And t_1.Dt_Pm_Id = '1920 ' And (t_0.Dr_Status = '1 ' Or t_0.Dr_Status = '2 ') And t_0.Dr_Dept_Id <> '2008 ' )

[解决办法]
luguo
[解决办法]
用union all 效率上没什么影响吧,不用的话如果是一张表就把所有条件集合到一起就行了!

热点排行