mysql练习题-查询同时参加计算机和英语考试的学生的信息-遁地龙卷风
(-1)写在前面
文章参考http://blog.sina.com.cn/willcaty。
针对其中的一道练习题想出两种其他的答案,希望网友给出更多回答。
(0) 基础数据
student表
+-----+--------+------+-------+------------+--------------+
| id | name | sex | birth | department | address |
+-----+--------+------+-------+------------+--------------+
| 901 | 张老大 | 男 | 1985 | 计算机系 | 北京市海淀区 |
| 904 | 李四 | 男 | 1990 | 英语系 | 辽宁省阜新市 |
| 905 | 王五 | 女 | 1991 | 英语系 | 福建省厦门市 |
| 906 | 王六 | 男 | 1988 | 计算机系 | 湖南省衡阳市 |
+-----+--------+------+-------+------------+--------------+
score表
+----+--------+-----------+-------+
| Id | Stu_id | C_Name | Grade |
+----+--------+-----------+-------+
| 23 | 901 | 计算机 | 98 |
| 24 | 901 | 英语 | 80 |
| 25 | 902 | 计算机 | 65 |
| 26 | 902 | 中文 | 88 |
| 27 | 903 | 中文 | 95 |
| 28 | 904 | 计算机 | 70 |
| 29 | 904 | 英语 | 92 |
| 30 | 905 | 英语 | 94 |
| 31 | 906 | 计算机 | 90 |
| 32 | 906 | 英语 | 85 |
+----+--------+-----------+-------+
(1)查询同时参加计算机和英语考试的学生的信息
方式一:
SELECT a.* FROM student a ,score b ,score c
WHERE a.id=b.stu_id
AND b.c_name='计算机'
AND a.id=c.stu_id
AND c.c_name='英语';
方式二:
SELECT * FROM student
WHERE id =ANY
( SELECT stu_id FROM score
WHERE stu_id IN (
SELECT stu_id FROM
score WHERE c_name= '计算机')
AND c_name= '英语' );
方式三:
select * from student where id in(
select s.stu_id from (select stu_id from score where c_name = '计算机') s
(select stu_id from score where c_name='英语') as t where s.stu_id=t.stu_id)
方式四:
select * from student where id in (
select stu_id from score where c_name ='计算机' and stu_id in(
select stu_id from score where c_name ='计算机'));
(2) 正确答案
+-----+--------+------+-------+------------+--------------+
| id | name | sex | birth | department | address |
+-----+--------+------+-------+------------+--------------+
| 901 | 张老大 | 男 | 1985 | 计算机系 | 北京市海淀区 |
| 904 | 李四 | 男 | 1990 | 英语系 | 辽宁省阜新市 |
| 906 | 王六 | 男 | 1988 | 计算机系 | 湖南省衡阳市 |
+-----+--------+------+-------+------------+--------------+

mysql练习题-查询同时参加计算机和英语考试的学生的信息-遁地龙卷风的更多相关文章
- MySQL中查询获取每个班级成绩前三名的学生信息
CREATE TABLE t_testscore( pk_id INT PRIMARY KEY, c_name VARCHAR(50) , c_score INT, c_class INT )DEFA ...
- MySQL练习题1
以下SQL操作均在MYSQL上测试过 首先是表定义 1.创建student和score表 CREATE TABLE student ( id ) NOT NULL UNIQUE PRIMARY KEY ...
- mysql经典查询语句-笔记
笔记来源公开课,谢谢! 1.创建student和score表 CREATE TABLE student ( id INT(10) NOT NULL UNIQUE PRIMARY KEY , name ...
- 笔记-4:mysql数据查询
1.创建查询表 1.1 创建班级表 含义 字段名 数据类型 宽度 班级编号 classNo 字符型 6 班级名称 className 字符型 20 所属院系 department 字符型 30 年级 ...
- mysql 分组查询前n条数据
今天去面试,碰到一道面试题: 有一个学生成绩表,表中有 表id.学生名.学科.分数.学生id .查询每科学习最好的两名学生的信息: 建表sql: CREATE TABLE `stuscore` ( ` ...
- MYSQL之查询篇
2. 数据库操作 数据库在创建以后最常见的操作便是查询 2.1 查询 为了便于学习和理解,我们预先准备了两个表分别是stduents表和classes表两个表的内容和结构如下所示 students表的 ...
- MySQL 表查询语句练习题
MySQL 表查询语句练习题: 一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表 ...
- MYSQL select查询练习题
10. 查询Score表中的最高分的学生学号和课程号.(子查询或者排序) select sno,cno from score where degree=(select max(degree) from ...
- mysql常见查询练习题
#建学生信息表student create table student ( sno varchar(20) not null primary key, sname varchar(20) not nu ...
随机推荐
- Linus:C++是一种糟糕的语言
本文内容摘自http://blog.csdn.net/turingbook/article/details/1775488 C++是一种糟糕的(horrible)语言.而且因为有大量不够标准的程序员在 ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- 【C#】toString("Format") 格式化
1..ToString("P");//得到小数点后2位的百分比,自动 加上%号;//9512.35% 这个比较厉害! furenjun yoolonet
- DeepMind背后的人工智能:深度学习原理初探
去年11月,一篇名为<Playing Atari with Deep Reinforcement Learning>的文章被初创人工智能公司DeepMind的员工上传到了arXiv网站.两 ...
- iOS开发--JS调用原生OC篇
JS调用原生OC篇 方式一(反正我不用) 第一种方式是用JS发起一个假的URL请求,然后利用UIWebView的代理方法拦截这次请求,然后再做相应的处理. 我写了一个简单的HTML网页和一个btn点击 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- celery使用方法
1.celery4.0以上不支持windows,用pip安装celery 2.启动redis-server.exe服务 3.编辑运行celery_blog2.py !/usr/bin/python c ...
- JavaScript replace() 方法
参考:http://www.w3school.com.cn/jsref/jsref_replace.asp 需要有一点注意的是:可以是函数的形式做为返回值,如下: "test{0}" ...
- mui 动态加载数据出现的问题处理 (silder )
mui-slider 问题:动态给mui的图片轮播添加图片,轮播不滚动. 解决:最后把滚动轮播图片的mui(".mui-slider").slider({interval: 300 ...
- js杂项
css是 下划线命名法:table_sub ;javascript ,net ,sql 全部是camel命名法 找临界点 1.elem.checked 有两个值,true,false . 页面中< ...