我有下表。
STUDENTS
+------+----------------+
| stuID| StuStatus |
+------+----------------+
| 1001 | 1 |
| 1001 | 3 |
| 1002 | 1 |
| 1003 | 6 |
| 1004 | 1 |
| 1002 | 4 |
| 1001 | 6 |
| 1005 | 1 |
| 1005 | 4 |
+------+----------------+
DESCRIPTION
+-------+--------------------------+
| statID| StatusDesc |
+-------+-------------------------+
| 1 | Application Submitted |
| 2 | Application Accepted |
| 3 | Application Pending |
| 4 | Application Resubmitted |
| 5 | Application Denied |
=+------+-------------------------+
如何利用内连接创建一个表格,以文字形式显示每个学生的起点和终点?
这是我现在脑子里的逻辑流程:
创建两个表,均包含stuID 和stuStatus 列。 这些表格将分别显示每个学生的最低和最高学习状态。
使用内部联接创建一个新表,其中我将“DESCRIPTION”联接到表 2 和表 3。
但是,我不清楚应该如何去做,并且希望得到一些帮助。
谢谢。
最佳答案
您应该首先确定每个学生的最低和最高状态,然后将这些数字转换为相应的描述。
像这样的事情:
SELECT stu_stat.stuID,
min_desc.statusDescr AS MinDescription,
max_desc.statusDescr AS MaxDescription
FROM
(
SELECT StuID,
MIN(StuStatus) AS MinStatus,
MAX(StuStatus) AS MaxStatus
FROM students
GROUP BY StuID
) AS stu_stat
JOIN descr_table AS min_desc
ON stu_stat.MinStatus = min_desc.StatID
JOIN descr_table AS max_desc
ON stu_stat.MaxStatus = max_desc.StatID;
不过我没试过...
关于mysql - 如何获取一个表的最小值和最大值并用它创建另一个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54870142/