数据库_初学语句 in的用法

之前因为需要 在长传日志表中通过上传时间查询基础信息表 用到了这些语句

--根据公司查上传时间
select distinct aae036 from CJSCRZ where CJGS=‘A‘
--根据上传时间查乡镇编号
select  distinct aae030   from CJSCRZ where aae036>=date‘2014-12-26‘and aae036<date‘2014-12-27‘ 


--根据乡镇编号查乡镇
select * from ab01 w where w.aaf030 in (select distinct aae030   from CJSCRZ where aae036>=date‘2014-12-26‘and aae036<date‘2014-12-27‘)    



--根据乡镇查各银行人数
select count(*) from ac01 where aaa148 like‘41102317%‘and yhmc =96288
select count(*) from ac01 where aaa148 like‘41102317%‘and yhmc =95580 
select count(*) from ac01 where aaa148 like‘41102314%‘and yhmc =96288



--查60岁以上
select count(*) from ac01 a where a .aaa148 like‘41102317%‘ and months_between(to_date(‘2014.12.29‘,‘yyyy.mm.dd‘),a.aac006)>720

 
select count(*) from ac01 a  where months_between(date‘2014-12-27‘,a.aac006)>720 and a.aaa148 like‘41102317%‘

  记下一些In的相关用法

SELECT "栏位名" 
FROM "表格名" 
WHERE "栏位名" IN (‘值一‘, ‘值二‘, ...)

 

在Where子句中可以使用IN操作符来查询其列值在指定的列表中的行。比如:查询出工作职责是SALESMAN、PRESIDENT或者ANALYST的员工。条件有两种表示方法:

  1. WHERE job = ‘SALESMAN ‘ OR job = ‘PRESIDENT ‘ OR job = ‘ANALYST ‘
  2. WHERE job IN (‘SALESMAN‘, ‘PRESIDENT‘, ‘ANALYST‘)

 

代码演示:IN操作

SQL> SELECT ENAME,JOB,SAL FROM EMP

2  WHERE job IN (‘SALESMAN‘, ‘PRESIDENT‘, ‘ANALYST‘);

ENAME

JOB

SAL

ALLEN

SALESMAN

1600

WARD

SALESMAN

1250

MARTIN

SALESMAN

1250

SCOTT

ANALYST

3000

KING

PRESIDENT

5000

TURNER

SALESMAN

1500

FORD

ANALYST

3000

7 rows selected

 

         对应IN操作的还有NOT IN,用法一样,结果相反。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。