Oracle 練習 1

Q1:

Write a query that returns those employees that don't make any commision and have a salary greater than 1100 but less than 5000. Exclude those employees that have a salary equal to 3000

A:

SELECT * 

FROM emp

WHERE ( comm IS NULL OR comm = 0)

AND sal > 1100 

AND sal < 5000

AND sal NOT IN 3000


EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
7698BLAKEMANAGER78391981/05/012850-30
7782CLARKMANAGER78391981/06/092450-10
7566JONESMANAGER78391981/04/022975-20
7844TURNERSALESMAN76981981/09/081500030
7934MILLERCLERK77821982/01/231300-10

另一種寫法:
SELECT * FROM EMP WHERE ( COMM IS NULL
AND SAL > 1100 AND SAL < 5000
AND SAL <> 3000 )
OR COMM = 0

Q2:
Returns those employees that are salesman and that make either 300 dollars in commission or greater than 1100 dollars in commission

A2:
SELECT * 
FROM emp
WHERE job = 'SALESMAN'
AND comm = 300 
OR comm > 1100

EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
7499ALLENSALESMAN76981981/02/20160030030
7654MARTINSALESMAN76981981/09/281250140030

0 Comments:

張貼留言