我有一张这样的表
id student teacher
10 a b
11 c b
12 d c
13 e b
学生“e”是第3名学生,其老师是“b”。 如何通过一个查询获得这个?
答案 0 :(得分:1)
你可以这样做:
SELECT * FROM (
SELECT @row := @row + 1 as row, t.* FROM student_table t, (SELECT @row := 0) r where t.teacher ='b'
) s where student = 'e'
答案 1 :(得分:1)
非常接近来自Secator的帖子
SELECT *
FROM (
SELECT (@row := @row + 1) AS rank, student
FROM my_table,
(SELECT @row := 0) q
WHERE teacher = 'b'
) s
WHERE student = 'e'