select 1 from 浅析

今天看到项目代码里有这条语句,不懂select 1 from XXXXXXX里的1是何意,查了一番才知道:

1、select 1 from mytable;与select anycol(目的表集合中的任意一行) from mytable;与select * from mytable 作用上来说是没有差别的,都是查看是否有记录,一般是作条件用的。select 1 from 中的1是一常量,查到的所有行的值都是它,但从效率上来说,1>anycol>*,因为不用查字典表。

2、查看记录条数可以用select sum(1) from mytable;等价于select sum(*) from mytable;

3、实际项目SQL:

  1. select c_insrnc_cde, c_nme_cn
  2.    from t_prd_ins a
  3. where a.c_prod_no = '01'
  4.     and not exists
  5. (select 1
  6.            from (select d.c_insrnc_cde, a.c_nme_cn
  7.                    from t_prd_ins                   a,
  8.                         tb_bas_ply_policy_rdr       c,
  9.                         tb_bas_ply_policy_rdr_list d
  10.                   where a.c_insrnc_cde = d.c_insrnc_cde
  11.                     and d.c_policy_id = c.c_policy_id
  12.                     and d.c_seq_no = c.c_seq_no
  13.                     and a.c_kind_no = '01'
  14.                     and c.c_dpt_cde = '101'   ----机构树中取出机构
  15.                     and c.c_prod_no = '01'
  16.                     and c.t_effc_tm <= TO_DATE('2007-9-5', 'YYYY-MM-DD')
  17.                     and c.t_expd_tm >= TO_DATE('2007-9-5', 'YYYY-MM-DD')
  18.                     and c.c_work_mode = '00501'
  19.                     and c.c_reach_area = '00701'
  20.                     ) t
  21.           where t.c_insrnc_cde = a.c_insrnc_cde);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值