简体   繁体   English

MySQL查询以查找一个表中一列的值是否在另一表中两列的两个值之间

[英]MySQL query to find if a value of one column in one table is between two values in two columns on another table

Long title question, so my apologies for that! 长标题问题,对此我深表歉意! I have two tables, one is as follows: 我有两个表,一个如下:

Student Name         Grade
John Doe             96
John Foe             65
Dan Doe              76
Mary Doe             85

The other table, is as follows: 另一个表如下:

Grade Start      Grade End       Status
0                60              Bad Student
61               70              OK Student
71               80              Good Student
81               90              Great Student
91               100             Honor Student

I am trying to create a MySQL view that will pull the student's grade, and tell me the status of that student such as: 我正在尝试创建一个MySQL视图,该视图将提高学生的成绩,并告诉我该学生的状态,例如:

Student Name     Grade      Status
John Doe         90         Honor Student
John Foe         65         OK Student

So on and so forth. 等等等等。 I can't think of a query that will give me that information. 我想不出一个可以提供该信息的查询。 I'm at a complete loss with the query, any help? 我对查询完全不知所措,有什么帮助吗?

SELECT student_name, student_grade from student_grade_table WHERE ???

Use a join: 使用联接:

SELECT s.student_name, s.grade, g.status
FROM students AS s
JOIN grades as g ON s.grade BETWEEN g.grade_start AND g.grade_end

DEMO 演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL查询将两列与另一张表中的一列进行比较(并获得两个值) - SQL Query to compare two columns with one column from another table (and get two values) mysql-表的两列和另一列的计数 - mysql - count of two columns of a table and one column from another 在mysql中创建表,其中一列包含另外两列的值的总和 - Create table in mysql with one column containing sum of another two columns value 将一个表的两列连接到另一表的一列 - Join two columns from one table to one column from another 如何将一个表中的两个或更多列与另一个表中的一个列联接在一起,即使第一个表列中的值为NULL - How to join two or more columns from one table with one column from another table, even there are NULL values in first table columns 将一个表的两列连接到另一表的同一列 - Join two columns of one table to the same column of another table Sequelize将一张表的两列连接到另一张表的同一列 - Sequelize join two columns of one table to the same column of another table 如何访问mysql中另一个表的两个不同列对应的表的一列? - How to access one column of a table corresponding to two different columns of another table in mysql? 根据另一个表中一列的总和在一个表中设置两个值 - Set two values in one table based on sum of a column in another table MySQL查找一个表中的记录,而该表没有另一表中的列的值 - MySQL Find records in one table that has no value of a column in another table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM