全境封锁靶场在哪里:sql高手请进!

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 22:10:27
有两个数据库表:employee包括字段code表示员工代码;name表示员工中文名,
gendate包括字段id为流水号,code表示员工代码,gendate为员工迟到日期,
如何用SQL语句完成搜索2005年12月没有迟到过的员工中文名?

复合性的查询
SELECT *
FROM table_name1
WHERE EXISTS (
SELECT *
FROM table_name2
WHERE conditions )
说明:
1.WHERE 的 conditions 可以是另外一个的 query。
2.EXISTS 在此是指存在与否。
SELECT *
FROM table_name1
WHERE column1 IN (
SELECT column1
FROM table_name2
WHERE conditions )
说明:
1. IN 后面接的是一个集合,表示column1 存在集合里面。
2. SELECT 出来的资料形态必须符合 column1。

select distinct a.name
from employee a left join gendate b
on a.code=b.code
where b.gendate between '2005-12-1' and '2006-1-1' and b.name is null

有人用not in,not in在in的结果集多的时候效率很低,并切如果结果集包含空记录的时候,所有的记录都被select 出来了

select distinct name from employee
where code not in
(
select code from gendate
where year(gendate) = 2005 and month(gendate) = 12
)

select * from employee a where not
exists(select 1 from gendate where code=a.code and
gendate between '20051201000000' and '20051231235959)