关于union all的 问题 ,求教。

稽姬 2007-08-30 05:04:40
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 来实现这个功能。多谢
...全文
262 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kinglht 2007-09-03
  • 打赏
  • 举报
回复
用union all 效率上没什么影响吧,不用的话如果是一张表就把所有条件集合到一起就行了!
liuzi123 2007-09-03
  • 打赏
  • 举报
回复
luguo
shan1119 2007-08-31
  • 打赏
  • 举报
回复
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' )
hongqi162 2007-08-30
  • 打赏
  • 举报
回复
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')

17,140

社区成员

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

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