2010年5月17日 星期一

5/18 2008 SQL homework1

USE sample




1. 從emp資料表中,找出公司薪資大於 2000元的員工,按照部門由低到高排列,部門相同時,按照薪資由高到低排列。


select EMPNO , ENAME , JOB , SAL , DEPTNO


from emp


where SAL > 2000


order by deptno , sal desc



2. 從emp資料表中,找出1981年進公司的員工,資淺的排前面。


select EMPNO , ENAME , HIREDATE , SAL ,DEPTNO


from emp


where hiredate between '1981-01-01' and '1981-12-31'


order by hiredate desc , sal desc


3. 從emp資料表中,找出職務是'CLERK'而且佣金是'NULL'的員工。

select empno,ename,job ,comm ,sal , deptno


from emp


where job='clerk' and comm is null


4. 從item資料表中,找出被訂購過的產品有那幾種,並按產品編號排序。

select distinct prodid


from ITEM


5. 在資料表customer中,找出客戶姓名最後一個字為「S」者。

select CUSTID , NAME ,phone as '電話',city


from CUSTOMER


where NAME like '%s'

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。