MySQL-- integrated query statements and Applications (Advanced) - who else? !
For more information about the database, please add attention yo ~ ~. For contact and want to install MySQL please Gabor Lord:
QQ: 3327908431
micro letter: ZDSL1542334210
Introduction: MySQL series of operations fierce as a tiger, the code clear and easy to understand, simple structure, today let's talk about some of the difficulty of MySQL inside of bias in the query. Although the difficulty a bit big, but I can give you blog friends ~ ~ clear who else? Ok? I would like to tidy hair ...
1, table creation
Creating student information table
create table stu(s_id varchar(5),
s_name varchar(5),
s_sex varchar(1),
s_age int(3),s_day date);
insert into stu values
("001","李华","男",23,'1996-8-16'),
("002","王二","男",24,'1997-3-16'),
("003","赵敏","女",23,'1990-5-26'),
("004","张莹莹","女",22,'1995-2-16'),
("005","朱亚军","男",25,'1999-8-16'),
("006","马云","男",28,'1993-12-16');
Create a table to get students scores
create table scores (s_id varchar(5),
c_id varchar(3),score float);
insert into scores values
("001","01",135),
("005","01",120),
("003","01",110),
("002","01",90),
("005","02",140),
("001","02",125.5),
("004","02",100),
("006","02",90),
("002","03",102),
("005","03",100.6),
("001","03",100),
("003","03",95.6),
("004","03",83),
("003","02",80),
("006","03",79.5);
2, section title
Topic one: the query than students numbered 002 students of all course grades are higher student information
analysis: All courses than 002 grades are high, means someone else's lowest scores are higher than the highest score of 002.
select stu.* from stu where s_id in
(select s_id from scores group by score having min(score)>
(select max(score) from scores where s_id=002));
# 答案
001 李华 男 23 1996-8-16
003 赵敏 女 23 1990-5-26
005 朱亚军 男 25 1999-8-16
Topic Two: inquiry average score of 100 points or greater student achievement information
select * from scores where s_id in
(select s_id from scores group by s_id having round(avg(score),2)>=100);
# 答案
001 01 135
005 01 120
005 02 140
001 02 125.5
005 03 100.6
001 03 100
Topic three: Discover the highest score for each subject score of each student
select * from scores group by c_id,s_id having max(score) order by c_id,score desc ;
# 答案
001 01 135
005 01 120
003 01 110
002 01 90
005 02 140
001 02 125.5
004 02 100
006 02 90
003 02 80
002 03 102
005 03 100.6
001 03 100
003 03 95.6
004 03 83
006 03 79.5
Topic Five: Query highest points score for each subject
select max(score) from scores group by c_id;
# 答案
135
140
102
Topic Six: finale title - second and third grades query information for each course (after reveal the answer)
3, the end of the paper eggs - easy moment
Well we all know, men to 17 and 18 years old it was somewhat what, you say my good friend Winnie appeared over this thing, before high school Well, we will talk about a girlfriend squad, but he also shared two , and then after a few weeks we eat together, since they lost not seen for several weeks, the results bear ridicule: "! you have to die sooner or later the kid in the woman," and then leave the squad mouth said: "you'll end up dead themselves hands! "and then bear silently bowed his head, looked at his right hand, did a lot of thick calluses than before ... Well is such a case.
Today to end here yo // each article has the end the egg - relaxed moment yo ~ plus interest to learn more about MySQL knowledge! Thank you for watching, I was Jetuser-data
Links: [https://blog.csdn.net/L1542334210]
CSND: L1542334210
I wish you all success! Family fun!