牛客網 資料庫SQL實戰10

2021-10-16 18:52:09 字數 3650 閱讀 2068

獲取所有非manager的員工emp_no

create

table

`dept_manager`

(`dept_no`

char(4

)not

null

,`emp_no`

int(11)

notnull

,`from_date`

date

notnull

,`to_date`

date

notnull

,primary

key(

`emp_no`

,`dept_no`))

;create

table

`employees`

(`emp_no`

int(11)

notnull

,`birth_date`

date

notnull

,`first_name`

varchar(14

)not

null

,`last_name`

varchar(16

)not

null

,`gender`

char(1

)not

null

,`hire_date`

date

notnull

,primary

key(

`emp_no`))

;

如插入為:

insert

into dept_manager values

('d001'

,10002

,'1996-08-03'

,'9999-01-01');

insert

into dept_manager values

('d002'

,10006

,'1990-08-05'

,'9999-01-01');

insert

into dept_manager values

('d003'

,10005

,'1989-09-12'

,'9999-01-01');

insert

into dept_manager values

('d004'

,10004

,'1986-12-01'

,'9999-01-01');

insert

into dept_manager values

('d005'

,10010

,'1996-11-24'

,'2000-06-26');

insert

into dept_manager values

('d006'

,10010

,'2000-06-26'

,'9999-01-01');

insert

into employees values

(10001

,'1953-09-02'

,'georgi'

,'facello'

,'m'

,'1986-06-26');

insert

into employees values

(10002

,'1964-06-02'

,'bezalel'

,'simmel'

,'f'

,'1985-11-21');

insert

into employees values

(10003

,'1959-12-03'

,'parto'

,'bamford'

,'m'

,'1986-08-28');

insert

into employees values

(10004

,'1954-05-01'

,'chirstian'

,'koblick'

,'m'

,'1986-12-01');

insert

into employees values

(10005

,'1955-01-21'

,'kyoichi'

,'maliniak'

,'m'

,'1989-09-12');

insert

into employees values

(10006

,'1953-04-20'

,'anneke'

,'preusig'

,'f'

,'1989-06-02');

insert

into employees values

(10007

,'1957-05-23'

,'tzvetan'

,'zielinski'

,'f'

,'1989-02-10');

insert

into employees values

(10008

,'1958-02-19'

,'saniya'

,'kalloufi'

,'m'

,'1994-09-15');

insert

into employees values

(10009

,'1952-04-19'

,'sumant'

,'peac'

,'f'

,'1985-02-18');

insert

into employees values

(10010

,'1963-06-01'

,'duangkaew'

,'piveteau'

,'f'

,'1989-08-24');

insert

into employees values

(10011

,'1953-11-07'

,'mary'

,'sluis'

,'f'

,'1990-01-22'

);

輸入描述:

無輸出描述:

用子查詢對select檢索出的表項進行篩選,可以用not in 和 not exists兩種方式

select emp_no

from employees

where emp_no notin(

select emp_no

from dept_manager )

select e.emp_no

from employees as e

where

notexists

(select

*from dept_manager as d

where e.emp_no = d.emp_no)

*

牛客網資料開發題庫 牛客網資料庫SQL實戰(1)

查詢最晚入職員工的所有資訊 入門 需要查詢最晚入職員工的資訊,即查詢hire date最大的資料,使用倒序並取第乙個人即可。select from employees order by hire date desc limit 0,1 desc 使用order by時在後面加上desc表示倒序,即從...

牛客網 資料庫SQL實戰36 40

36.對於如下表actor,其對應的資料為 actor id first name last name last update 1penelope guiness 2006 02 15 12 34 33 2nick wahlberg 2006 02 15 12 34 33 建立乙個actor nam...

牛客網 資料庫SQL實戰1

題目描述 查詢最晚入職員工的所有資訊,為了減輕入門難度,目前所有的資料裡員工入職的日期都不是同一天 sqlite裡面的注釋為 mysql為comment create table employees emp no int 11 notnull 員工編號 birth date date notnull...