有三个表。 学生,室友,工资。列如下
student
student_id (Primary Key) | smallint
student_name | varchar(30)
roommate
student_id (Primary Key) | smallint
roommate_id | smallint
salary
student_id (Primary Key) | smallint
salary | float(10,2)
现在我需要打印学生的姓名和他们的室友相同。 好吧,我能够找到薪水相同的人。但是我找不到他们是否是室友。该怎么做?
答案 0 :(得分:1)
以下是对MySQL有帮助的查询
def doStuff():
global selected
selected = lb.curselection()
if selected: # only perform if user made a selection
for index in selected:
selection = (lb.get(index))# how you get the value of the selection from a listbox
print(selection)
```
希望这会有所帮助
答案 1 :(得分:0)
SELECT st.student_name FROM student st /* st - Student */
JOIN roommate rm ON (rm.student_id = st.student_id) /* rm - Student roommate */
JOIN salary st_salary ON (st.student_id = st_salary.student_id) /* st_salary - student's salary */
JOIN salary rm_salary ON /* (rm.roommate_id = rm_salary.student_id) /* rm_salary - student'ts roomate salary */
WHERE st_salary.salary = rm_salary.salary;