MYSQL - 使用innerjoin和过滤记录

时间:2016-02-10 22:36:46

标签: mysql sql inner-join

我有两个mysql表

Students
StudentNo  StudentName
1000       Harvey Specter
1002       Mike Ross
1003       Louis Litt

fees
ORnum  StudentNo AmtPd     PaymentMode
1      1001      1600.00   Cash
2      1002      3000.00   Installment
3      1002      5000.00   Installment
4      1002      1500.00   Installment
5      1003      10500.00  Cash

使用INNER JOIN,我正在寻找以下输出

Student Name   Amount   Mode of Payment
Mike Ross      3000     Installment  
Mike Ross      5000     Installment
Mike Ross      1500     Installment

1 个答案:

答案 0 :(得分:1)

您要找的是学生和学费表之间的INNER JOIN。您希望使用WHERE子句进行过滤。

SELECT s.studentName as Student_Name, f.amount as Amount, f.PaymentMode as Mode of Payment 
FROM students s
INNER JOIN fees f
ON s.StudentNo = f.StudentNo
WHERE s.studentName = 'Mike Ross'

请看一下这个SQL Fiddle

http://sqlfiddle.com/#!9/3ae1a2/3/0