SQL Server 2008R2 的 OFFSET 不起作用
OFFSET with SQL Server 2008R2 doesn't work
我的 table 中有大约 24000000 个修订,但是当我尝试获取 1 到 100 行之间时,查询会花费很多时间。
我尝试使用 OFFSET
,因为它在 SQL Server 2008 R2 上与 SQL Server 2012 不一样。
我的 SQL 查询如下所示:
SELECT
CAST(rev_date AS varchar) Rev_Date,
CAST(username AS varchar) UserName,
CAST(rev AS varchar) Rev,
CAST(rev_type AS varchar) Rev_Type,
CAST(id_cl AS varchar) id,
CAST(id_ AS varchar) abstract,
CAST(id AS varchar) participant,
CAST(id_ref_decl_channel AS varchar) refDecChannel,
CAST(old_sherpa_number AS varchar) oldSherpaNumber,
CAST(is_notifier AS varchar) notify,
CAST(is_declarer AS varchar) declarer,
CAST(dispatch_rate AS varchar) dispatchRate
FROM
(SELECT
CAST(inf.rev_date AS varchar) Rev_Date,
CAST(inf.username AS varchar) UserName,
CAST(aud.rev AS varchar) Rev,
CAST(aud.rev_type AS varchar) Rev_Type,
CAST(aud.id_cl AS varchar) id,
CAST(aud.id_ AS varchar) abstract,
CAST(aud.id AS varchar) participant,
CAST(aud.id_ref_decl_channel AS varchar) refDecChannel,
CAST(aud.old_sherpa_number AS varchar) oldSherpaNumber,
CAST(aud.is_notifier AS varchar) notify,
CAST(aud.is_declarer AS varchar) declarer,
CAST(aud.dispatch_rate AS varchar) dispatchRate,
ROW_NUMBER() OVER (ORDER BY SalesOrderDetailID) AS RowNum
FROM
oth_aud aud, ref.rev_info inf
WHERE
aud.rev = inf.id_rev_info AND aud.rev_type = 0) AS SOD
WHERE
SOD.RowNum BETWEEN 1 AND 100
我想通过偏移这个原理,在我的网页中使用分页。
我知道有很多解决方案,例如 jQuery 的数据 table,但我想使用 SQL 服务器。
有什么建议吗?
OFFSET 存在于 SQL Server 2012
我的 table 中有大约 24000000 个修订,但是当我尝试获取 1 到 100 行之间时,查询会花费很多时间。
我尝试使用 OFFSET
,因为它在 SQL Server 2008 R2 上与 SQL Server 2012 不一样。
我的 SQL 查询如下所示:
SELECT
CAST(rev_date AS varchar) Rev_Date,
CAST(username AS varchar) UserName,
CAST(rev AS varchar) Rev,
CAST(rev_type AS varchar) Rev_Type,
CAST(id_cl AS varchar) id,
CAST(id_ AS varchar) abstract,
CAST(id AS varchar) participant,
CAST(id_ref_decl_channel AS varchar) refDecChannel,
CAST(old_sherpa_number AS varchar) oldSherpaNumber,
CAST(is_notifier AS varchar) notify,
CAST(is_declarer AS varchar) declarer,
CAST(dispatch_rate AS varchar) dispatchRate
FROM
(SELECT
CAST(inf.rev_date AS varchar) Rev_Date,
CAST(inf.username AS varchar) UserName,
CAST(aud.rev AS varchar) Rev,
CAST(aud.rev_type AS varchar) Rev_Type,
CAST(aud.id_cl AS varchar) id,
CAST(aud.id_ AS varchar) abstract,
CAST(aud.id AS varchar) participant,
CAST(aud.id_ref_decl_channel AS varchar) refDecChannel,
CAST(aud.old_sherpa_number AS varchar) oldSherpaNumber,
CAST(aud.is_notifier AS varchar) notify,
CAST(aud.is_declarer AS varchar) declarer,
CAST(aud.dispatch_rate AS varchar) dispatchRate,
ROW_NUMBER() OVER (ORDER BY SalesOrderDetailID) AS RowNum
FROM
oth_aud aud, ref.rev_info inf
WHERE
aud.rev = inf.id_rev_info AND aud.rev_type = 0) AS SOD
WHERE
SOD.RowNum BETWEEN 1 AND 100
我想通过偏移这个原理,在我的网页中使用分页。
我知道有很多解决方案,例如 jQuery 的数据 table,但我想使用 SQL 服务器。
有什么建议吗?
OFFSET 存在于 SQL Server 2012