我有一个名为pluginProspects
的SQL Server表,我有以下列..
FirstName
LastName
Email
AmonutOfEmployees
AnnualRevenue
在这个表中,我有数千行,我想创建一个SQL语句,允许我检索行200 - 300甚至行300 - 400或我想要的行。
我用以下代码工作了一段时间,但是我想添加特定的WHERE
条款并且它没有显示100个结果,它显示我像50或70或w / e取决于这些特定行号的结果
SELECT *
FROM
(SELECT
ROW_NUMBER() OVER (ORDER BY demoID DESC) AS rownum,
demoID, RecordStatus, Email, FirstName, LastName, AmountOfEmployees,
AnnualRevenue
FROM
pluginProspects) AS Salaries1
WHERE
rownum BETWEEN 1 * {STARTNUMBERHERE} - 100 AND 1 * {STARTNUMBERHERE}
AND (RecordStatus = '2014 Lead')
AND (AmonutofEmployees > 10)
ORDER BY
AmountOfEmployees DESC
正如你所看到的{STARTNUMBERHERE}
我可以把100,200,300,400等用来创建一个非常好的分页效果直到我添加(AmountofEmployees > 10)
在我的表中,有大量的潜在客户少于10名员工,因此有时只显示10或20个结果,而不是前100个结果。
任何人都知道我应该这样做的正确方法吗?不,我不能使用存储过程来做我想做的事情,它必须是基于纯SQL的
答案 0 :(得分:1)
马特,
Max意味着将其更改为
SELECT *
FROM
(SELECT
ROW_NUMBER() OVER (ORDER BY demoID DESC) AS rownum,
demoID, RecordStatus, Email, FirstName, LastName, AmountOfEmployees,
AnnualRevenue
FROM
pluginProspects
WHERE (RecordStatus = '2014 Lead')
AND (AmonutofEmployees > 10) ) AS Salaries1
WHERE
rownum BETWEEN 1 * {STARTNUMBERHERE} - 100 AND 1 * {STARTNUMBERHERE}
ORDER BY
AmountOfEmployees DESC