(文末有数据库代码)
1、 查询全部图书的图书号、作者、出版社和单价;
select bno as ‘图书号’,author as ‘作者’,publish as ‘出版社’,price as ‘单价’
from book;
2、 查询全体图书的信息,其中单价打8折,并设置该列的别名为“打折价”;
select ,price0.8 as ‘打折价’ from book;
3、 显示所有借过书的借阅者的读者号、并去掉重复行;
select distinct rno from borrow ;
4、 查询所有单价在20-30元之间的图书信息;
select * from book where price between 20 and 30;
5、 查询所有单价不在20-30元之间的图书信息;
select * from book where price<20 or price>30;
6、 查询机械工业出版社、科学出版社、人民邮电出版社的图书信息;
select * from book
where publish=‘机械工业出版社’ or publish=‘科学出版社’
or publish=‘人民邮电出版社’;
7、 查询既不是机械工业出版社也不是科学出版社出版的图书信息;
select * from book
where publish!=‘机械工业出版社’ and publish!=‘科学出版社’;
8、 查询姓名的第二个字符是‘建’并且只有两个字符的读者的 读者号及姓名
select rno,rname from reader where rname like ‘_建’;

9、 查找姓名以‘王’开头的所有读者的读者号及姓名;
select rno,rname from reader where rname regexp ‘^王’;

10、 查找姓名以王、张、或李开头的所有读者的读者号及姓名;
select rno,rname from reader where rname like ‘王%’ or rname like ‘李%’ or rname like ‘张%’;
11、 查询无归还日期的借阅信息;
select * from borrow where rdate is null;
12、 查询有归还日期的借阅信息;
select * from borrow where rdate is not null;
13、 查询单价在20元以上、30元以下的机械工业出版社出版的图书名及单价;
select bname,price from book where publish=‘机械工业出版社’ and price between 20 and 30;
14、 查询机械工业出版社或科学出版社出版的图书名、出版社及单价;
select bname,publish,price from book where publish=‘机械工业出版社’ or publish=‘科学出版社’;
15、 查询读者的总人数;
select count() from reader;
16、 查询借阅了图书的读者的总人数;
select count(
) from reader where rno in(
select rno from borrow);

17、 查询机械工业出版社图书的平均价格、最高价、最低价;
select avg(price) as ‘平均价格’,max(price) as’最高价’,min(price) as ‘最低价’
from book where publish=‘机械工业出版社’;
18、 查询借阅图书数超过2本的读者号、总本书,并按照借阅本数从大到小排序;
select rno ,count() from borrow group by rno
having count(
)>2 order by count() desc;
19、 查询读者的基本信息及其借阅情况(借阅情况指历史借阅数量,在借数量);
select r.rno as ‘读者号’,r.rname as ‘姓名’,count(
) as ‘历史借阅量’,
count(*)-count(b.rdate) as ‘在借数量’
from borrow as b inner join reader as r on r.rno=b.rno
group by b.rno;

20、 查询读者的读者号、姓名、借阅的图书名、借出日期及归还日期,并按照读者号作升序排序;

select r.rno as ‘读者号’,r.rname as ‘姓名’,b.rdate,b.bdate from borrow as b
inner join reader as r on r.rno=b.rno
inner join book as bk on bk.bno=b.bno
ORDER BY b.rno;
21、 查询借阅了机械工业出版社,并且书名包含‘数据库’三个字的图书的读者,并显示读者号、姓名、书名、出版社、借出日期及归还日期;
select r.rno as ‘读者号’,r.rname as ‘姓名’,bk.bname,bk.publish,b.rdate,b.bdate from borrow as b
inner join reader as r on r.rno=b.rno
inner join book as bk on bk.bno=b.bno
where bk.publish=‘机械工业出版社’;
22、 查询至少借阅过1本机械工业出版社的图书的读者的 读者号、姓名、借阅本数,并按借阅本数多少排序;
select r.rno as ‘学号’,r.rname as ‘姓名’,count() as ‘历史借阅量’
from borrow as b
inner join reader as r on r.rno=b.rno
inner join book as bk on bk.bno=b.bno
where bk.publish=‘机械工业出版社’
group by b.rno having count(
)>=1;

23、 查询与‘王小平’的办公电话相同的读者的姓名(王小平本人不再列出);
select rname from reader where rname!=‘王小平’ and tel in(
select tel from reader where rname=‘王小平’);

24、 查询办公电话为‘88320701’的所有读者的借阅情况,要求包含借阅了图书的读者和没有借阅的读者,
显示他们的读者号、姓名、书名及借阅日期;

select reader.rno as ‘学号’,reader.rname as ‘姓名’,book.bname,b.rdate
from borrow as b
RIGHT JOIN reader using(rno)
LEFT JOIN book using(bno);

25、 查询所有单价小于平均单价的图书的书号、书名及出版社;
select bno,bname,publish from book where price<(select avg(price) from book);
26、 查询‘科学出版社’的图书的单价比‘机械工业出版社’最高单价还高的图书书名及单价;
select bname,price from book where publish=‘科学出版社’ and
price>(select max(price) from book where publish=‘机械工业出版社’);
27、 查询已经被借阅过并已经归还的图书信息;
select * from book where bno in (select bno from borrow where bdate is not null and rdate is not null)

28、 查询从未被借阅过的图书信息;
select * from book where bno not in (select bno from borrow )
29、 查询正在被借阅的图书信息;
select * from book where bno in (select bno from borrow where rdate is null)
30、 查询软件系借了书还没有还的读者学号姓名。
select DISTINCT r.rno as ‘学号’,r.rname as ‘姓名’
from borrow as b
inner join reader as r on r.rno=b.rno
inner join book as bk on bk.bno=b.bno
where b.rdate is null;
31、 查询借阅图书总数最多的宿舍楼
select reader.address from reader
left join borrow using(rno)
GROUP BY reader.address ORDER BY count(borrow.bno) desc LIMIT 1;

**

数据库表

**

create database library;use library

接着直接复制下面的代码输进MySQL终端

SET FOREIGN_KEY_CHECKS=0;-- ----------------------------
-- Table structure for book
-- ----------------------------
DROP TABLE IF EXISTS `book`;
CREATE TABLE `book` (`bno` char(20) NOT NULL,`bname` varchar(50) DEFAULT NULL,`author` varchar(30) DEFAULT NULL,`publish` varchar(50) DEFAULT NULL,`price` float(255,0) DEFAULT NULL,PRIMARY KEY (`bno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ----------------------------
-- Records of book
-- ----------------------------
INSERT INTO `book` VALUES ('111100', '科学出版社历史丛书', '科学', '科学出版社', '108');
INSERT INTO `book` VALUES ('111111', '数据库编程', '张作家', '机械工业出版社', '56');
INSERT INTO `book` VALUES ('222222', '数据库开发', '西红柿', '清华大学出版社', '66');
INSERT INTO `book` VALUES ('333333', '猛兽岛大逃亡', '梦里水乡', '机械工业出版社', '55');
INSERT INTO `book` VALUES ('444444', 'SQL数据库案例', '茶香', '科学出版社', '12');
INSERT INTO `book` VALUES ('555555', '思维导论', 'jison', '机械工业出版社', '65');
INSERT INTO `book` VALUES ('666666', '算法设计', 'jim', '清华大学出版社', '22');
INSERT INTO `book` VALUES ('777777', 'mysql数据库入门', 'kimi', '机械工业出版社', '96');
INSERT INTO `book` VALUES ('888888', '疯狂英语', 'katy', '科学出版社', '33');
INSERT INTO `book` VALUES ('999999', '世界地图', '位居士大夫', '机械工业出版社', '88');-- ----------------------------
-- Table structure for borrow
-- ----------------------------
DROP TABLE IF EXISTS `borrow`;
CREATE TABLE `borrow` (`rno` char(8) NOT NULL,`bno` char(20) NOT NULL,`bdate` char(8) NOT NULL,`rdate` char(8) DEFAULT NULL,KEY `rno` (`rno`),KEY `bno` (`bno`),CONSTRAINT `bno` FOREIGN KEY (`bno`) REFERENCES `book` (`bno`),CONSTRAINT `rno` FOREIGN KEY (`rno`) REFERENCES `reader` (`rno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ----------------------------
-- Records of borrow
-- ----------------------------
INSERT INTO `borrow` VALUES ('0001', '111111', '20150403', '20160406');
INSERT INTO `borrow` VALUES ('0001', '333333', '20150206', '20160407');
INSERT INTO `borrow` VALUES ('0002', '222222', '20150207', '20160408');
INSERT INTO `borrow` VALUES ('0002', '555555', '20150208', '20160409');
INSERT INTO `borrow` VALUES ('0003', '444444', '20150209', '20160410');
INSERT INTO `borrow` VALUES ('0008', '444444', '20171012', null);
INSERT INTO `borrow` VALUES ('0009', '999999', '20171215', null);
INSERT INTO `borrow` VALUES ('0002', '222222', '20171116', null);
INSERT INTO `borrow` VALUES ('0003', '666666', '20184545', null);
INSERT INTO `borrow` VALUES ('0003', '888888', '20171141', null);
INSERT INTO `borrow` VALUES ('0002', '888888', '20170678', null);-- ----------------------------
-- Table structure for reader
-- ----------------------------
DROP TABLE IF EXISTS `reader`;
CREATE TABLE `reader` (`rno` char(10) NOT NULL,`rname` char(8) NOT NULL,`sex` char(2) NOT NULL,`tel` char(8) DEFAULT NULL,`department` varchar(30) DEFAULT NULL,`address` varchar(30) DEFAULT NULL,PRIMARY KEY (`rno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ----------------------------
-- Records of reader
-- ----------------------------
INSERT INTO `reader` VALUES ('0001', '张三', '1', '87818112', '软件', '尚品书院');
INSERT INTO `reader` VALUES ('0002', '李建', '0', '87818283', '网络', null);
INSERT INTO `reader` VALUES ('0003', '王小平', '0', '88320701', '游戏', '尚品书院');
INSERT INTO `reader` VALUES ('0004', '王祝福', '1', '88320701', '游戏', null);
INSERT INTO `reader` VALUES ('0005', '高多多', '1', '87818998', '会计', '华软1号楼');
INSERT INTO `reader` VALUES ('0006', '瑞安', '0', '88320701', '游戏', null);
INSERT INTO `reader` VALUES ('0007', '斯琴', '1', '88320701', '游戏', '绿映楼');
INSERT INTO `reader` VALUES ('0008', '迪迪', '0', '88320701', '游戏', '蓝楹楼');
INSERT INTO `reader` VALUES ('0009', '热吧', '1', '87818282', '工商', '蓝楹楼');
INSERT INTO `reader` VALUES ('0010', '李四四', '1', '8789', '软件', '蓝楹楼');
INSERT INTO `reader` VALUES ('0011', '张四', '1', '8989741', '软件', '尚品书院');

MySQL数据库操作练习题-各种操作掌握MySQL查询操作相关推荐

  1. mye连接mysql数据库_MySQL_如何在Java程序中访问mysql数据库中的数据并进行简单的操作,在上篇文章给大家介绍了Myeclip - phpStudy...

    如何在Java程序中访问mysql数据库中的数据并进行简单的操作 在上篇文章给大家介绍了Myeclipse连接mysql数据库的方法,通过本文给大家介绍如何在Java程序中访问mysql数据库中的数据 ...

  2. mysql练习题解题_2016年计算机二级考试MySQL数据库章节练习题

    一.选择题 不可对视图执行的操作有_______. A)SELECT B)INSERT C)DELETE D)CREATE INDEX 二.填空题 1.在MySQL中,可以使用_______语句创建视 ...

  3. mysql数据库入门第二张试卷_2016计算机二级《MySQL数据库》练习题与答案

    2016计算机二级<MySQL数据库>练习题与答案 一.选择题 下列语句中,________不是表数据的基本操作语句. A)CREATE语句 B)INSERT语句 C)DELETE语句 D ...

  4. 电脑上mysql数据库无法登录_无法远程登入MySQL数据库的几种解决办法MySQL综合 -电脑资料...

    方法一: 尝试用MySQL Adminstrator GUI Tool登入MySQL Server,Server却回复错误讯息:Host '60-248-32-13.HINET-IP.hinet.ne ...

  5. linux下使用的mysql数据库,Linux下安装以及使用MySQL数据库

    1.官网下载mysql数据库:https://dev.mysql.com/downloads/mysql/ 2.linux 下可直接下载:wget https://cdn.mysql.com//Dow ...

  6. Mysql数据库基本操作(七)多表查询-子查询,表自身关联查询

    多表查询还有前面的两块内容--内连接查询,外连接查询,希望看到这篇博客的朋友先去看看我的"Mysql数据库"专栏中Mysql数据库基本操作(六)多表查询-内连接,外连接这一章博客, ...

  7. MySQL数据库教程之十五:MySQL触发器实例

    MySQL数据库教程之十五:MySQL触发器实例 准备工作: 先启动Navicat for MySQL,建立数据库 建立两个表:Goods(商品表).Orders(订单表) Goods(商品表) cr ...

  8. Mysql数据库基本操作(六)多表查询-内连接查询,外连接查询

    数据准备 use mydb3 ; --创建部门表 create table if not exists dept3 ( deptno varchar (20) primary key , --部门号 ...

  9. MySQL数据库test连接语句_【MySQL数据库开发之二】MySQL 基础语句的书写与操作!...

    本篇Himi简单介绍一些MySQL数据库的基础操作: 注:mysql 语句对大小写不敏感,语句以分号";"标识语句结束: 1.   首先使用两个简单的查询语句: 查询当前版本:se ...

  10. java连接mysql数据库增删改查_java连接mysql数据库增删改查操作记录

    1. 连接数据库.得到数据库连接变量 注意连接数据库的时候 (1)打开DB Browser 新建一个Database Driver,注意加入Driver JARs的时候加入的包,我的是mysql-co ...

最新文章

  1. 场效应管的判别、检测及使用时的注意事项!
  2. 2020-12-3(详解虚拟地址如何转化为物理地址)
  3. 安卓软件错误log_Android编程实现捕获程序异常退出时的错误log信息功能详解
  4. birt中文手册在线_QGIS简体中文翻译现状
  5. 剑指offer面试题06. 从尾到头打印链表(辅助栈法)
  6. 【学习】如何用jQuery获取iframe中的元素
  7. 数据中台公开课丨可以复用的中台架构建设经验与实践
  8. 关于BMZCTF hitcon_2017_ssrfme的解法
  9. python基于大数据的食物推荐系统
  10. STM32 USART 多摩川编码器调试
  11. tomcat集群(小型项目)
  12. 火云邪神ddos使用_ddos攻击器怎么用
  13. idea自定义banner
  14. Python教程视频千锋最新版免费分享
  15. ie浏览器 “嗯...无法访问页面 尝试此操作...”的解决办法
  16. Linux多网卡多路由设置
  17. website for all kinds of courses
  18. 创客匠人教您实现流量变现
  19. DeepLabv3+
  20. 独数,python,C代码实现

热门文章

  1. reset.css(常用项目代码初始化)
  2. Nuxt - 自定义配置修改顶部加载条颜色(loding)
  3. java中的steam流
  4. 键盘怎么一按f1就出计算机,电脑每次开机都要按F1键,且开机后都会弹出一个打开方式的窗口,请问该怎么处理?...
  5. 什么样的程序员适合去创业公司
  6. 软件测试的目的和意义是什么?
  7. #define 和typedef的区别
  8. Muti-Similarity Loss:考虑了batch中整体距离分布的对比损失函数
  9. 游戏制作之路-unity捕鱼达人(一 开始以及加载界面的制作)
  10. 软考时间管理思维导图