According to the structure of the table, use the sql statement to query and
build the table SQL as follows:
create table stu_grade(name varchar(20),coursevarchar(20),grade int);
– Insert data
INSERT INTO stu_grade
VALUES ('Zhang San','语文', '81');
INSERT INTO stu_grade
VALUES ('Zhang San','Mathematics', '75');
INSERT INTO stu_grade
VALUES ('李四','语文', ' 76');
INSERT INTO stu_grade
VALUES ('李四','Mathematics', '90');
INSERT INTO stu_grade
VALUES ('王五','语文', '81');
INSERT INTO stu_grade
VALUES ('王五', ' Math', '100');
INSERT INTO stu_grade
VALUES ('Wang Wu','English', '90');
Query the names of students whose scores are greater than 80 in each course:
select distinct name from stu_grade where name not in(select distinct name from stu_grade where grade <=80);
There is another way
select name from stu_grade group by name HAVING MIN(grade) > 80;
Extension:
SQL SELECT distinct statement
Concept:
In the table, there may be duplicate values. This is not a problem, but sometimes you may wish to list only distinct values
Syntax:
SELECT DISTINCT column name FROM table name
When there are multiple identical values in the result set, if you need unique different values, use the distinct statement.
Two w3Schools need unique values. At this time,
SELECT DISTINCT Company FROM Orders
is now in the result. Centralized, "W3School" is listed only once.