我有这两张桌子:
master(专业、SID、费用)
Biology, 13578, $500
Physics, 12460, $400
学生(专业、SID、fname、lname、startDate、lastDate)
Science, 73589, Steven, Archer, 2010-09-02, null
Biology, 13578, Stacy, Diaz, 2009-09-02, null
Sociology, 21749, Gavin, Wall, 2011-01-05, null
Physics, 12460, Pat, Dunn, 2012-09-02, null
我必须查询它显示按专业和费用分组的所有硕士生的信息。
我试过这样:
select * from from master, student
where master.SID=student.SID AND master.major=student.major
group by student.SID;
但这会使 SID 和主要信息显示两次:
Biology, 13578, Stacy, Diaz, 2009-09-02, null, Biology, 13578
Physics, 12460, Pat, Dunn, 2012-09-02, null, Physics, 12460
所以现在我有了这个:
select distinct student.sid, student.eid, fname, lname, startDate, lastDate, fee
from from master, student
where master.SID=student.SID AND master.major=student.major
group by student.SID;
这将给出:
Biology, 13578, Stacy, Diaz, 2009-09-02, null
Physics, 12460, Pat, Dunn, 2012-09-02, null
但我想知道是否有办法不指定选择哪个 SID 或专业。我希望它全选,但它会删除重复项。
对不起,如果这看起来很容易,我还是 mysql 的初学者