將Java進(jìn)行到底
          將Java進(jìn)行到底
          posts - 15,  comments - 66,  trackbacks - 0

          /*
          建表:
          dept:
           deptno(primary key),dname,loc
          emp:
           empno(primary key),ename,job,mgr,sal,deptno
          */

          1 列出emp表中各部門的部門號(hào),最高工資,最低工資
          select max(sal) as 最高工資,min(sal) as 最低工資,deptno from emp group by deptno;

          2 列出emp表中各部門job為'CLERK'的員工的最低工資,最高工資
          select max(sal) as 最高工資,min(sal) as 最低工資,deptno as 部門號(hào) from emp where job = 'CLERK' group by deptno;

          3 對(duì)于emp中最低工資小于1000的部門,列出job為'CLERK'的員工的部門號(hào),最低工資,最高工資
          select max(sal) as 最高工資,min(sal) as 最低工資,deptno as 部門號(hào) from emp as b
          where job='CLERK' and 1000>(select min(sal) from emp as a where a.deptno=b.deptno) group by b.deptno

          4 根據(jù)部門號(hào)由高而低,工資有低而高列出每個(gè)員工的姓名,部門號(hào),工資
          select deptno as 部門號(hào),ename as 姓名,sal as 工資 from emp order by deptno desc,sal asc

          5 寫出對(duì)上題的另一解決方法
          (請(qǐng)補(bǔ)充)

          6 列出'張三'所在部門中每個(gè)員工的姓名與部門號(hào)
          select ename,deptno from emp where deptno = (select deptno from emp where ename = '張三')

          7 列出每個(gè)員工的姓名,工作,部門號(hào),部門名
          select ename,job,emp.deptno,dept.dname from emp,dept where emp.deptno=dept.deptno

          8 列出emp中工作為'CLERK'的員工的姓名,工作,部門號(hào),部門名
          select ename,job,dept.deptno,dname from emp,dept where dept.deptno=emp.deptno and job='CLERK'

          9 對(duì)于emp中有管理者的員工,列出姓名,管理者姓名(管理者外鍵為mgr)
          select a.ename as 姓名,b.ename as 管理者 from emp as a,emp as b where a.mgr is not null and a.mgr=b.empno

          10 對(duì)于dept表中,列出所有部門名,部門號(hào),同時(shí)列出各部門工作為'CLERK'的員工名與工作
          select dname as 部門名,dept.deptno as 部門號(hào),ename as 員工名,job as 工作 from dept,emp
          where dept.deptno *= emp.deptno and job = 'CLERK'

          11 對(duì)于工資高于本部門平均水平的員工,列出部門號(hào),姓名,工資,按部門號(hào)排序
          select a.deptno as 部門號(hào),a.ename as 姓名,a.sal as 工資 from emp as a
          where a.sal>(select avg(sal) from emp as b where a.deptno=b.deptno) order by a.deptno

          12 對(duì)于emp,列出各個(gè)部門中平均工資高于本部門平均水平的員工數(shù)和部門號(hào),按部門號(hào)排序
          select count(a.sal) as 員工數(shù),a.deptno as 部門號(hào) from emp as a
          where a.sal>(select avg(sal) from emp as b where a.deptno=b.deptno) group by a.deptno order by a.deptno

          13 對(duì)于emp中工資高于本部門平均水平,人數(shù)多與1人的,列出部門號(hào),人數(shù),按部門號(hào)排序
          select count(a.empno) as 員工數(shù),a.deptno as 部門號(hào),avg(sal) as 平均工資 from emp as a
          where (select count(c.empno) from emp as c where c.deptno=a.deptno and c.sal>(select avg(sal) from emp as b where c.deptno=b.deptno))>1
          group by a.deptno order by a.deptno

          14 對(duì)于emp中低于自己工資至少5人的員工,列出其部門號(hào),姓名,工資,以及工資少于自己的人數(shù)
          select a.deptno,a.ename,a.sal,(select count(b.ename) from emp as b where b.sal<a.sal) as 人數(shù) from emp as a
          where (select count(b.ename) from emp as b where b.sal<a.sal)>5


          轉(zhuǎn)自:http://blog.csdn.net/woolceo/archive/2006/03/02/614094.aspx

          posted on 2006-03-04 20:31 風(fēng)蕭蕭 閱讀(2046) 評(píng)論(1)  編輯  收藏 所屬分類: 雜談

          FeedBack:
          # re: 轉(zhuǎn):數(shù)據(jù)庫筆試題
          2008-06-02 16:55 | 啊啊啊
          對(duì)面試很有幫助!  回復(fù)  更多評(píng)論
            

          <2006年3月>
          2627281234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          常用鏈接

          留言簿(8)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊(cè)

          收藏夾

          myfriends

          opensource

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 娄烦县| 吉安县| 周宁县| 塔城市| 天津市| 乐清市| 江城| 扎兰屯市| 和田县| 阿尔山市| 鹤壁市| 建水县| 普陀区| 乌拉特后旗| 七台河市| 修武县| 洪江市| 芦山县| 德格县| 黄陵县| 临泽县| 嘉定区| 刚察县| 元朗区| 泊头市| 甘谷县| 汉源县| 余姚市| 黔西| 浦城县| 正安县| 昭平县| 财经| 海丰县| 平阳县| 赫章县| 伊川县| 榆中县| 滦平县| 沁水县| 江孜县|