日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql面试题1

發(fā)布時間:2024/1/8 数据库 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql面试题1 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

MySQL實訓_01
1. 創(chuàng)建數(shù)據(jù)庫,名稱為cdadb;(如果已有,則省略)
2. 創(chuàng)建數(shù)據(jù)表customer(客戶)、deposite(存款)、bank(銀行),表結(jié)構(gòu)如下:
customer的表結(jié)構(gòu):
屬性名稱 類型與長度 中文含義 備注
c_id char(6) 客戶標識 主鍵,非空
name varchar(30) 客戶姓名 非空
location Varchar(30) 工作地點
salary decimal(8,2) 工資
bank的表結(jié)構(gòu):
屬性名稱 類型與長度 中文含義 備注
b_id char(5) 銀行標識 主鍵,非空
bank_name char(30) 銀行名次 非空
deposite的表結(jié)構(gòu):
屬性名稱 類型與長度 中文含義 備注
d_id int 存款流水號 主鍵,非空,自增
c_id char(6) 客戶標識 外鍵,關(guān)聯(lián)customer表的c_id
b_id char(5) 銀行標識 外鍵,關(guān)聯(lián)bank表的b_id
dep _date date 存入日期
dep_type char(1) 存款期限 1,3,5分別代表1年期、3年期和5年期
amount decimal(8,2) 存款金額
3. 錄入數(shù)據(jù)如下:
customer的數(shù)據(jù)如下,注意最后一條記錄用你的學號和你的姓名代替。
c_id name location salary
101001 孫楊 廣州 1234
101002 郭海 南京 3526
101003 盧江 蘇州 6892
101004 郭惠 濟南 3492
你的學號 你的姓名 北京 6324

bank的數(shù)據(jù)如下:
b_id bank_name
B0001 工商銀行
B0002 建設(shè)銀行
B0003 中國銀行
B0004 農(nóng)業(yè)銀行
deposite的數(shù)據(jù)如下:
d_id c_id b_id dep_date dep_type amount
1 101001 B0001 2011-04-05 3 42526
2 101002 B0003 2012-07-15 5 66500
3 101003 B0002 2010-11-24 1 42366
4 101004 B0004 2008-03-31 1 62362
5 101001 B0003 2002-02-07 3 56346
6 101002 B0001 2004-09-23 3 353626
7 101003 B0004 2003-12-14 5 36236
8 101004 B0002 2007-04-21 5 26267
9 101001 B0002 2011-02-11 1 435456
10 101002 B0004 2012-05-13 1 234626
11 101003 B0003 2001-01-24 5 26243
12 101004 B0001 2009-08-23 3 45671
4. 更新customer表的salary屬性,將salary低于5000的客戶的salary變?yōu)樵瓉淼?倍.
5. 對deposite表進行統(tǒng)計,按銀行統(tǒng)計存款總數(shù),顯示為b_id,total.
6. 對deposite、customer、bank進行查詢,查詢條件為location在廣州、蘇州、濟南的客戶,存款在300000至500000之間的存款記錄,顯示客戶姓名name、銀行名稱bank_name、存款金額amount.

關(guān)系型數(shù)據(jù)庫和MySQL作業(yè)

作業(yè):使用下面的SQL在MySQL中創(chuàng)建數(shù)據(jù)庫、二維表并插入數(shù)據(jù),然后完成下面的查詢操作。

create database hrs default charset utf8mb4;use hrs;create table tb_dept ( dno int not null comment '編號', dname varchar(10) not null comment '名稱', dloc varchar(20) not null comment '所在地', primary key (dno) );insert into tb_dept values (10, '會計部', '北京'),(20, '研發(fā)部', '成都'),(30, '銷售部', '重慶'),(40, '運維部', '深圳');create table tb_emp ( eno int not null comment '員工編號', ename varchar(20) not null comment '員工姓名', job varchar(20) not null comment '員工職位', mgr int comment '主管編號', sal int not null comment '員工月薪', comm int comment '每月補貼', dno int comment '所在部門編號', primary key (eno), foreign key (dno) references tb_dept(dno), foreign key (mgr) references tb_emp(eno) );insert into tb_emp values (7800, '張三豐', '總裁', null, 9000, 1200, 20),(2056, '喬峰', '分析師', 7800, 5000, 1500, 20),(3088, '李莫愁', '設(shè)計師', 2056, 3500, 800, 20),(3211, '張無忌', '程序員', 2056, 3200, null, 20),(3233, '丘處機', '程序員', 2056, 3400, null, 20),(3251, '張翠山', '程序員', 2056, 4000, null, 20),(5566, '宋遠橋', '會計師', 7800, 4000, 1000, 10),(5234, '郭靖', '出納', 5566, 2000, null, 10),(3344, '黃蓉', '銷售主管', 7800, 3000, 800, 30),(1359, '胡一刀', '銷售員', 3344, 1800, 200, 30),(4466, '苗人鳳', '銷售員', 3344, 2500, null, 30),(3244, '歐陽鋒', '程序員', 3088, 3200, null, 20),(3577, '楊過', '會計', 5566, 2200, null, 10),(3588, '朱九真', '會計', 5566, 2500, null, 10);
  • 查詢月薪最高的員工姓名和月薪

    mysql> select ename as 姓名,sal as 月薪 from tb_emp where sal = (select max(sal) f rom tb_emp);
  • 查詢員工的姓名和年薪((月薪+補貼)*13)

    mysql> select ename as 姓名,(sal+ifnull(comm,0))*13 as 年薪 from tb_emp;
  • 查詢所有部門的名稱和人數(shù)

    mysql> select dname as 部門,total as 人數(shù) from tb_dept d left join (select dno,count(dno) as total from tb_emp group by dno) e on d.dno = e.dno;
  • 查詢月薪最高的員工(Boss除外)的姓名和月薪

    mysql> select ename as 姓名,sal as 月薪 from tb_emp where sal = (select max(sal) from tb_emp where job !='總裁');
  • 查詢月薪超過平均月薪的員工的姓名和月薪

    mysql> select ename as 姓名,sal as 月薪 from tb_emp where sal > (select avg(sal) from tb_emp);
  • 查詢月薪超過其所在部門平均月薪的員工的姓名、部門編號和月薪

    mysql> select e.ename as 姓名,d.dno as 部門編號,e.sal as 月薪 from tb_emp e inner join (select dno,avg(sal) as avgsal from tb_emp group by dno) as d on d.dno =e.dno where e.sal > d.avgsal;
  • 查詢部門中月薪最高的人姓名、月薪和所在部門名稱

    # 1 部門中月薪最高的拿出來 SELECT dno,max(sal) as maxsal from tb_emp GROUP BY dno;# 2 部門中月薪最高的人 部門編號 拿出來 SELECT ename,sal,t1.dno from tb_emp t1 INNER JOIN (SELECT dno,max(sal) as maxsal from tb_emp GROUP BY dno) t2 on t1.dno=t2.dno where sal=maxsal; # 3 根據(jù)上表 拿出 部門名稱 mysql> select e.ename as 姓名,p.dname as 部門名稱,e.sal as 月薪 from tb_emp e inner join (select dno,max(sal) as maxsal from tb_emp group by dno) d on d.dno = e.dno inner join tb_dept p on d.dno =p.dno where e.sal = d.maxsal;
  • 查詢主管的姓名和職位

    SELECT eno,ename,job from tb_emp where eno in (SELECT DISTINCT mgr from tb_emp where mgr is not null);
  • 查詢月薪排名4~6名的員工排名、姓名和月薪

  • SELECT @n:=@n+1 as rank, ename,sal from tb_emp,(SELECT @n:=0) t1 ORDER BY sal desc; SELECT ename,rank,sal from (SELECT @n:=@n+1 as rank, ename,sal from tb_emp,(SELECT @n:=0) t1 ORDER BY sal desc) t2 LIMIT 3,3;SELECT (select count(eno) from tb_emp t2 where t1.sal<t2.sal) as '排名',t1.ename as '姓名',t1.sal as '月薪' from tb_emp t1 where t1.sal in (SELECT sal from tb_sal) ORDER BY t1.sal desc;create table tb_sal(SELECT DISTINCT sal from tb_emp ORDER BY sal desc limit 3,3);
  • 有員工的部門編號和人數(shù)

    SELECT dno,COUNT(dno) as 人數(shù) from tb_emp GROUP BY dno;
  • 總結(jié)

    以上是生活随笔為你收集整理的mysql面试题1的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。