sql语句练习

Posted 蜜桃婷婷酱

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql语句练习相关的知识,希望对你有一定的参考价值。

分享一些sql语句联系题,4个表的关联,sql语句答案不唯一,可以当成练习使用,聚合函数 in,between and,having,order by,group by,limit,case when关键字语法都有用到 还挺综合,我写的应该有错的 欢迎大家下方评论留言

以下为4个表的数据结构




以下为创建表的语句,直接选择数据库执行即可,如果是dbeaver客户端,可能需要删除这句直接创建 DROP TABLE IF EXISTS grade;

/*
Navicat mysql Data Transfer

Source Server         : 本地mysql
Source Server Version : 50715
Source Host           : localhost:3306
Source Database       : geminno_day_07

Target Server Type    : MYSQL
Target Server Version : 50715
File Encoding         : 65001

Date: 2017-07-11 19:16:14
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for grade
-- ----------------------------
DROP TABLE IF EXISTS `grade`;
CREATE TABLE `grade` (
  `GradeId` varchar(255) DEFAULT NULL,
  `GradeName` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of grade
-- ----------------------------
INSERT INTO `grade` VALUES ('1', 'S1');
INSERT INTO `grade` VALUES ('2', 'S2');
INSERT INTO `grade` VALUES ('3', 'S3');

-- ----------------------------
-- Table structure for result
-- ----------------------------
DROP TABLE IF EXISTS `result`;
CREATE TABLE `result` (
  `Id` varchar(255) DEFAULT NULL,
  `StudentNo` varchar(255) DEFAULT NULL,
  `SubjectId` varchar(255) DEFAULT NULL,
  `StudentResult` varchar(255) DEFAULT NULL,
  `ExamDate` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of result
-- ----------------------------
INSERT INTO `result` VALUES ('1', 'S1201302001', '1', '80', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('2', 'S1201302002', '1', '45', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('3', 'S1201302001', '2', '90', '2013/10/18 星期五');
INSERT INTO `result` VALUES ('5', 'S1201302002', '2', '60', '2013/10/18 星期五');
INSERT INTO `result` VALUES ('12', 'S2102001', '3', '76', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('13', 'S2102002', '3', '90', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('14', 'S2102003', '3', '99', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('15', 'S2102004', '3', '79', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('16', 'S2102005', '3', '80', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('17', 'S2102006', '3', '61', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('18', 'S2102007', '3', '82', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('19', 'S2102008', '3', '35', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('20', 'S2102009', '3', '64', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('21', 'S2102010', '3', '65', '2013/9/13 星期五');
INSERT INTO `result` VALUES ('22', 'S1101001', '1', '80', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('23', 'S1101002', '1', '61', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('24', 'S1101003', '1', '82', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('25', 'S1101004', '1', '55', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('26', 'S1101005', '1', '64', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('27', 'S1101006', '1', '65', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('28', 'S1101007', '1', '88', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('29', 'S1101008', '1', '67', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('30', 'S1101009', '1', '68', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('31', 'S1101010', '1', '44', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('32', 'S1101011', '1', '89', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('33', 'S1101012', '1', '71', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('34', 'S1101013', '1', '44', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('35', 'S1101014', '1', '77', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('36', 'S1101015', '1', '86', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('37', 'S1101016', '1', '75', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('38', 'S1101017', '1', '76', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('39', 'S1101018', '1', '90', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('40', 'S1101019', '1', '99', '2013/12/22 星期日');
INSERT INTO `result` VALUES ('41', 'S1101020', '1', '79', '2013/12/23 星期一');
INSERT INTO `result` VALUES ('42', 'S1101001', '2', '80', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('43', 'S1101002', '2', '61', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('44', 'S1101003', '2', '82', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('45', 'S1101004', '2', '35', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('46', 'S1101005', '2', '64', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('47', 'S1101006', '2', '65', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('48', 'S1101007', '2', '88', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('49', 'S1101008', '2', '67', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('50', 'S1101009', '2', '68', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('51', 'S1101010', '2', '44', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('52', 'S1101011', '2', '75', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('53', 'S1101012', '2', '71', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('54', 'S1101013', '2', '44', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('55', 'S1101014', '2', '88', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('56', 'S1101015', '2', '86', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('57', 'S1101016', '2', '75', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('58', 'S1101017', '2', '38', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('59', 'S1101018', '2', '90', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('60', 'S1101019', '2', '99', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('61', 'S1101020', '2', '79', '2013/11/15 星期五');
INSERT INTO `result` VALUES ('62', 'S1101011', '1', '68', '2013/7/1 星期一');
INSERT INTO `result` VALUES ('63', 'S1101014', '1', '75', '2013/7/1 星期一');
INSERT INTO `result` VALUES ('64', 'S1101008', '2', '45', '2013/7/1 星期一');
INSERT INTO `result` VALUES ('65', 'S1101014', '2', '60', '2013/7/1 星期一');
INSERT INTO `result` VALUES ('66', 'S2102001', '8', '99', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('67', 'S2102002', '8', '55', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('68', 'S2102003', '8', '60', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('69', 'S2102004', '8', '70', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('70', 'S2102005', '8', '85', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('71', 'S2102006', '8', '88', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('72', 'S2102007', '8', '95', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('73', 'S2102008', '8', '44', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('74', 'S2102009', '8', '68', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('75', 'S2102010', '8', '88', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('76', 'S2102011', '8', '88', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('77', 'S1101001', '3', '88', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('78', 'S1101002', '3', '50', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('79', 'S1101003', '3', '44', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('80', 'S1101004', '3', '77', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('81', 'S1101005', '3', '75', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('82', 'S1101006', '3', '63', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('83', 'S1101007', '3', '15', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('84', 'S1101008', '3', '55', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('85', 'S1101009', '3', '69', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('86', 'S1101010', '3', '90', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('87', 'S1101011', '3', '95', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('88', 'S1101001', '4', '99', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('89', 'S1101002', '4', '60', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('90', 'S1101003', '4', '65', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('91', 'S1101004', '4', '77', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('92', 'S1101005', '4', '75', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('93', 'S1101006', '4', '63', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('94', 'S1101007', '4', '45', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('95', 'S1101008', '4', '55', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('96', 'S1101009', '4', '69', '2013/3/22 星期五');
INSERT INTO `result` VALUES ('97', 'S1101010', '4', '90',以上是关于sql语句练习的主要内容,如果未能解决你的问题,请参考以下文章

MYBATIS05_ifwherechoosewhentrimsetforEach标签sql片段

Pikachu漏洞练习平台实验——SQL注入

sql语句练习

MySql练习---[SQL查询语句练习]

MySQL[练习]SQL 语句

复杂sql语句练习