赞
踩
头歌MySQL数据库代码、答案,单表查询、连接查询、子查询
目录
- USE Company;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## retrieving the Name and Salary ##########
- select Name,Salary from tb_emp;
-
- ########## retrieving all the table ##########
- select * from tb_emp;
-
- ########## End ##########
- USE Company;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## retrieving the Name and Salary with IN statement ##########
- SELECT Name,Salary FROM tb_emp WHERE Id NOT IN (1);
-
-
- ########## End ##########
-
- USE Company;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## retrieving the Name and Salary with BETWEEN AND statement ##########
- SELECT Name,Salary FROM tb_emp
- WHERE Salary BETWEEN 3000 AND 5000;
-
-
- ########## End ##########
-
- USE Company;
-
- ######### Begin #########
- SELECT Name,Salary FROM tb_emp WHERE Name LIKE "C%";
-
- ######### End #########
-
-
- USE Company;
-
- ######### Begin #########
- SELECT * FROM tb_emp WHERE DeptId IS NULL;
-
- ######### End #########
-
- ######### Begin #########
- SELECT DISTINCT Name FROM tb_emp;
-
- ######### End #########
-
-
- USE Company;
-
- ######### Begin #########
- SELECT * FROM tb_emp WHERE DeptId=301 AND Salary > 3000;
-
- ######### End #########
-
- ######### Begin #########
- SELECT * FROM tb_emp WHERE DeptId=301 OR DeptId=303;
-
- ######### End #########
- USE School;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## 查询1班同学的所有信息以成绩降序的方式显示结果 ##########
- select * from tb_score where class_id = 1 order by score desc;
-
- ########## End ##########
-
-
- USE School;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## 对班级名称进行分组查询 ##########
- SELECT * FROM tb_class GROUP BY class_id;
-
- ########## End ##########
- USE School;
-
- #请在此处添加实现代码
- ########## Begin ##########
-
- ########## 查询班级中第2名到第5名的学生信息 ##########
- SELECT * FROM tb_score order by score desc LIMIT 1,4;
-
- ########## End ##########
- USE School;
-
- ########## 查询数据表中学生姓名和对应的班级 ##########
- #请在此处添加实现代码
- ########## Begin ##########
- select tb_student.name as studentName,tb_class.name as className from tb_student join tb_class on tb_class.id = tb_student.class_id;
-
-
-
- ########## End ##########
-
-
- USE School;
-
- ########## 使用左外连接查询所有学生姓名和对应的班级 ##########
-
- #请在此处添加实现代码
- ########## Begin ##########
- select tb_student.name as studentName,tb_class.name as className
- from tb_class right join tb_student on
- tb_class.id=tb_student.class_id;
-
-
-
- ########## End ##########
-
- ########## 使用右外连接查询所有学生姓名和对应的班级 ##########
- select tb_student.name as studentName,tb_class.name as className
- from tb_class left join tb_student
- on tb_class.id=tb_student.class_id;
- #请在此处添加实现代码
- ########## Begin ##########
-
-
-
-
- ########## End ##########
- USE School;
-
- ########## 查询所有班级里分数在90分以上的学生的姓名和学生的成绩以及学生所在的班级 ##########
- #请在此处添加实现代码
- ########## Begin ##########
- select s1.name as studentName,score,
- s2.name as className from tb_student as s1,
- tb_class as s2 where s1.class_id=s2.id and
- s1.score>90 order by score desc;
- ########## End ##########
- USE Company;
-
- #请在此处添加实现代码
- ########## Begin ##########
- #1.查询大于所有平均年龄的员工姓名与年龄
- select name,age from tb_emp where age>(select avg(age) from tb_emp);
-
-
- ########## End ##########
- USE Company;
- #请在此处添加实现代码
- ########## Begin ##########
-
- #1.使用 ALL 关键字进行查询
- SELECT position,salary FROM tb_salary WHERE salary >
- ANY(SELECT max(salary) FROM tb_salary where position="java");
- #2.使用 ANY 关键字进行查询
- SELECT position,salary FROM tb_salary WHERE salary >
- ANY(SELECT min(salary) from tb_salary where position="java");
- #3.使用 IN 关键字进行查询
- select position,salary from tb_salary where position in("java");
- ########## End ##########
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。