这个不起作用
select count(*) from table where col = 'value' order by id desc limit 100
错误:identifier 'id' unknown
这也无效
select count(*) from (select * from table order by id desc limit 100) as temp where col = 'value'
错误:syntax error, unexpected ORDER, expecting UNION or EXCEPT or INTERSECT or ')'
如果我使用offset ...
代替order by ... desc limit ...
- syntax error, unexpected OFFSET
我找到的唯一方法是获取表中所有行的计数和
select count(*) from (select ROW_NUMBER() over () as n, table.* from table) as temp where n > %COUNT% - 100 and col = 'value'
有没有更好的方法来计算N个最后一行?