mysql - How to I get the minimum and maximum value of a table and create another table with it?
问题描述
I have the following tables.
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 |
=+------+-------------------------+
How do i make use of inner join to create a table that shows for each student, their start point and end point, in words?
This is the logic flow I have in my mind right now:
Create two tables, both with the columns stuID and stuStatus. The tables will demonstrate each student's min and max stuStatus respectively.
Create a new table using inner join, where I join DESCRIPTION to my table 2 and 3.
However, I am not clear of how I should go about doing it and would love some help.
Thank you.
解决方案
您应该首先确定每个学生的最低和最高状态,然后将这些数字转换为相应的描述。
像这样的东西:
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;
虽然我没试过...
推荐阅读
- python - 将字母字符串转换为列表
- ruby-on-rails - 在 Rails 中使用设计,尝试在注册后添加第二步以更新用户的姓名、简历和照片
- java - 当我按下按钮时,如何在另一个活动中创建一个新的 TextView?
- python - 获取多个子元素 XML 的值
- python - Torchvision.transforms 的 Flatten() 实现
- python - 如何合并三个列表并将答案作为列表返回
- go - 将 JSON 响应传递到 Go 模板
- printing - 有没有办法将金属输出捕获为位图或其他适合打印的格式?
- vhdl - 如何实例化采用通用包的组件?
- javascript - 以一种形式添加/编辑多个资源