oracle中in用法的优化,使用not in的如何优化

8楼结果不对

SQL> with SIGN_DETAIL_INFO (userName,signDate)

2  as(

3  select 1 , date'2019-1-18' from dual union

4  select 1 , date'2019-1-19' from dual union

5  select 2 , date'2019-1-18' from dual union

6  select 2 , date'2019-1-20' from dual)

7  select a.userName

8    from SIGN_DETAIL_INFO a

9  where a.signDate between

10         to_date('2019-01-17 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and

11         to_date('2019-01-18 00:00:00', 'yyyy-mm-dd hh24:mi:ss')

12     and a.userName not in

13         (select a.userName

14            from SIGN_DETAIL_INFO a

15           where signDate =

16                 to_date('2019-01-19 00:00:00', 'yyyy-mm-dd hh24:mi:ss'));

USERNAME

----------

2

已用时间:  00: 00: 00.01

SQL>

SQL>

SQL> with SIGN_DETAIL_INFO (userName,signDate)

2  as(

3  select 1 , date'2019-1-18' from dual union

4  select 1 , date'2019-1-19' from dual union

5  select 2 , date'2019-1-18' from dual union

6  select 2 , date'2019-1-20' from dual)

7  select a.userName

8    from SIGN_DETAIL_INFO a

9  where signDate between date '2019-01-17' and date '2019-01-19'

10  group by userName

11  having count(case when signDate=date '2019-01-19' then 1 end)=0;

USERNAME

----------

2

已用时间:  00: 00: 00.00

SQL>

SQL>

SQL> with SIGN_DETAIL_INFO (userName,signDate)

2  as(

3  select 1 , date'2019-1-18' from dual union

4  select 1 , date'2019-1-19' from dual union

5  select 2 , date'2019-1-18' from dual union

6  select 2 , date'2019-1-20' from dual)

7  select userName from ( select case when signDate=date '2019-01-19' then null else  a.userName end userName

8    from SIGN_DETAIL_INFO a

9  where a.signDate between

10         to_date('2019-01-17 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and

11         to_date('2019-01-19 00:00:00', 'yyyy-mm-dd hh24:mi:ss')) where userName is not null;

USERNAME

----------

1

2

已用时间:  00: 00: 00.01

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值