表:用户、学生、组
用户:
行:Username
值:Teacher1Teacher2Teacher3Teacher4
学生:
行:grpIDName
价值观:(1,约翰),(1,乔),(1,罗斯),(2,吉娜),(2,马克),(2,杰克),(3,泰德),(4,弗雷德)
组:
行:grpIDHandler
值(1,teacher1),(2,teacher2),(3,teacher3),(4,teacher4)
php - 什么是对此的正确查询。 (需要orderby,使一些值最后和更多)MYSQL-LMLPHP
我想在有人登录时查询(比如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`;

07-24 17:15