按Y列排序
X Y Z
------------------------
| | A1 | |
------------------------
| | B2 | |
------------------------
| | C3 | |
------------------------ -----Page 1
| | D3 | |
------------------------
| | E4 | |
------------------------
| | F5 | |
------------------------ -----Page 2
| | G5 | |
------------------------
| | F6 | |
------------------------
| | G7 | | -----Page 3 用户可以选择输入通配符搜索,即- "%5“
我想返回到用户页面2(因为它有一些东西第一次出现,然后是5。)或者找出包含F5的列之前有多少行
(带C应用编程接口的SQLite)
发布于 2010-09-11 02:58:53
假设MySQL,按X和X排序的结果集是唯一的:
SELECT COUNT(*)
FROM mytable
WHERE X <
(
SELECT X
FROM mytable
WHERE y LIKE '%5'
ORDER BY
X
LIMIT 1
)发布于 2010-09-11 03:12:28
假设使用MSSQL,这里有一种绕过逻辑的方法..如果没有帮助,请告诉我:
declare @perPage int
declare @searchString varchar(20)
declare @countBefore int
declare @firstMatch varchar(20)
declare @resultPage int
set @perPage = 3
set @searchString = '%5'
select @firstMatch = (select top 1 y from myTable where y like @searchString order by y)
select @countBefore = (select count(*) from myTable where y < @firstMatch)
select @resultPage = (@countBefore / @perPage) + 1https://stackoverflow.com/questions/3687495
复制相似问题