我想选择按DESC排序的前n条记录,那么需要找到存在于这些前n条记录中的surround='',下面是jdbc SQL查询中的表格,供参考。
SELECT Count(*) FROM (SELECT TOP 2 * FROM fchild where vehicle='43' ORDER BY id DESC) where vehicle = '43' AND surround ='16';
vehicle surround Iter id
31 31 1 1
31 65 2 2
6 6 1 3
6 74 1 4
34 34 1 5
43 43 2 6
37 37 1 7
37 73 1 8
43 16 1 9
80 7 2 10
62 62 1 11
43 35 1 12
SELECT Count(*) FROM (SELECT TOP 2 * FROM fchild where vehicle='43' ORDER BY id DESC) a where vehicle = '43' AND surround ='16';
这对我来说是可行的。你忘记了子查询的名称(在我的例子中是'a')。我对问题的理解正确吗?