mysql練習02

來源:互聯網
上載者:User

標籤:art   dna   視圖   style   view   span   系統   table   max   

職工系統:

設有關係職工表(職工號empno,職工名ename,部門號deptno,工資sal)和部門表(部門號deptno,部門名dname,主任manager),用SQL陳述式完成下列要求:

create table emp (

empno int(10) primary key,

ename varchar(20),

deptno int(10),

sal decimal(10,2)

);

 

create table department (

deptno int(10) primary key,

dname varchar(20),

manager varchar(20)

);

 

 

根據題目的關鍵字自行構建測試資料(比較重要)

 

  (1)向職工表中插入行(‘025’,‘王芳’,‘03’,1000)

insert into emp values(‘025‘, ‘王芳‘, ‘03‘, ‘1000‘);

  (2)從職工表中刪除人事處的所有員工

delete from emp where deptno = (select deptno from department where dname = ‘人事處‘);

  (3)將職工號為‘001’的員工工資改為700元錢

update emp set sal = ‘700‘ where empno = ‘001‘;

  (4)查詢人事處的員工最高工資

select max(sal) from emp where deptno = (select deptno from department where dname = ‘人事處‘);

  (5)查詢“王芳”所在部門的部門主任

select manager from department where deptno = (select deptno from emp where ename = ‘王芳‘);

(6)查詢與“王芳”在同一部門的其它員工資訊

select * from emp where deptno = (select deptno from emp where ename = ‘王芳‘) and ename not like ‘王芳‘;

  (7)建立公司所有部門的公用視圖——部門職工視圖

create view dept_sta_view(empno, ename, deptno, sal, dname, mgr) as select a.empno, a.ename, a.deptno, a.sal, b.dname, b.manager from emp a, department b where a.deptno = b.deptno;

  (8)從部門職工視圖中查詢財務處員工工資高於800元的員工資訊

select * from dept_sta_view where sal > ‘800‘ and dname = ‘財務處‘;

 

mysql練習02

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.