089 where後面的列子查詢

2021-10-17 03:32:56 字數 2008 閱讀 5068

多行子查詢

多行比較操作符

innot in

anysom

allin 與 =any 等價

not in 與 <>all 等價

#返回location_id是1400或1700的部門中的所有員工姓名

#1產尋location是1400、1700的部門編號

select

distinct department_id

from departments

where location_id in

(1400

,1700

)select last_name

from

`employees`

where department_id in

(select

distinct department_id

from departments

where location_id in

(1400

,1700))

;

#題目:返回其它工種中比job_id為『it_prog』部門任一工資低的員工的#員工號、姓名、job_id 以及salary

select

distinct salary

from employees

where job_id=

'it_prog'

;select

`employee_id`

,`last_name`

,`job_id`

,`salary`

from

`employees`

where salary<

any(

select

distinct salary

from employees

where job_id=

'it_prog'

)and job_id<>

'it_prog'

;#或者

select

`employee_id`

,`last_name`

,`job_id`

,`salary`

from

`employees`

where salary<

any(

select

max(salary)

#比較from employees

where job_id=

'it_prog'

)and job_id<>

'it_prog'

;

#題目:返回其它部門中比job_id為『it_prog』部門所有工資都低的員工的員工號、姓名、job_id 以及salary

select

`employee_id`

,`last_name`

,`job_id`

,`salary`

from

`employees`

where salary<

all(

select

distinct salary

from employees

where job_id=

'it_prog'

)and job_id<>

'it_prog'

;#或者

select

`employee_id`

,`last_name`

,`job_id`

,`salary`

from

`employees`

where salary<

any(

select

min(salary)

from employees

where job_id=

'it_prog'

)and job_id<>

'it_prog'

;

where後面的行子查詢使用

行子查詢 結果集一行多列或多行多列 案例 查詢員工編號最小並且工資最高的員工資訊 select from employees where employee id,salary select min employee id max salary from employees 1.查詢員工編號最小 se...

090 where後面的行子查詢

查詢員工編號最小並且工資最高的員工資訊 此員工不一定存在 以前的做法 select from employees where employee id select min employee id from employees and salary select max salary from emp...

HiveQL中where後面的and 和or 處理

昨天我在嘗試寫乙個很簡單的hiveql 語句如下 select a.ver,a.vid,a.wid,a.type,count from select stat date,ver,get json object json,vid as vid,get json object json,wid as w...