表:用户、学生、组
用户:
行:Username
值:Teacher1
,Teacher2
,Teacher3
,Teacher4
学生:
行:grpID
,Name
价值观:(1,约翰),(1,乔),(1,罗斯),(2,吉娜),(2,马克),(2,杰克),(3,泰德),(4,弗雷德)
组:
行:grpID
,Handler
值(1,teacher1),(2,teacher2),(3,teacher3),(4,teacher4)
我想在有人登录时查询(比如teacher1)
Select `Name` from Students where (I don't know the proper condition here) Order by `Name`
但我想要的结果是:
Fred
Gina
Jack
Mark
Ted
Joe
John
Rose
我希望Teacher1处理的这3个学生(作为登录的示例用户)是查询结果中显示的最后一条记录。
最佳答案
有些事情是这样的
select `name` from Students
inner join Groups on Students.groupID = Groups.grpID
where groups.Handler = 'Teacher1'
order by `name`;
否则如果你想让学生点名,你只需要用
Select `name` from Students
order by `name`;