我已经关注了我的sql查询,我想从另一个表中获取限制启动索引,我该怎么办?
SELECT std.totalmarks
FROM student as std
WHERE std.status=1
ORDER BY (std.datetime) ASC
LIMIT (
SELECT us.startnum
FROM user AS us
WHERE us.username='abc'
),10
答案 0 :(得分:2)
select * from
(SELECT std.totalmarks, numstart.startnum, @n:=@n+1 as number
FROM student as std,
(SELECT us.startnum
FROM user AS us
WHERE us.username='abc') as numstart,
(SELECT @n:=0) sess_var
WHERE std.status=1
ORDER BY (std.datetime) ASC) res
where number>=startnum
LIMIT 0,10
答案 1 :(得分:2)
select q.totalmarks from
(
SELECT *,@curRow := @curRow + 1 AS row_number
FROM student as std JOIN (SELECT @curRow := 0) r
WHERE std.status=1
ORDER BY (std.datetime) ASC
) q
where row_number>(
SELECT us.startnum
FROM user AS us
WHERE us.username='abc'
)
limit 10