-1

I need a little input on using views. So I have a view with some values. Now in that view I want to do the following:

Grab a value from a MYSQL table and do a look up for that value from another table(this table has ranges), the tables are all in the same databases.

So for example, I am using value 10 from table 1. Now I want to look up that value in table 2 and extract the other columns from it,so the final columns(output) I'll get in my view are

10 | Bad Grade | PASS

Table 2 Example (3 columns)

1-6   | Good Grade | PASS
7-11  | Bad Grade  | PASS
12-16 | Fail       | DIDNT PASS
4

1 回答 1

-1
select students.*
from students
join(gradeComments) on(students.grade>=gradeComments.minGrade and students.grade<=gradeComments.maxGrade)

(是的,我是一个不喜欢 MySQL 大写查询的叛逆者。)

此外,您需要将表 2 中的最小值和最大值分别放在两个单独的列中。您需要一个显示“7”的最小列和一个显示“11”的最大列,而不是显示“7-11”的列。

以上应显示“students”(表1)表中的每一行,并将其与适当的“gradeComment”(表2)行链接。这是你要找的吗?

于 2013-07-10T03:39:18.817 回答