首页 > 代码库 > 数据库_初学语句 in的用法

数据库_初学语句 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 =96288select 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,用法一样,结果相反。

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