计算并集的第二页结果
我遇到了 SQLServer 问题。
我正在尝试弄清楚如何显示第二页结果。使用下面的查询提取第一页结果。
SELECT TOP 10 * FROM (
SELECT c.id, c.name, c.inserteddate, c.cityname, ftblstates.name AS statename, clc.name AS catname, '' AS listingimagelogo, '' AS orgname, relocateyn, '' AS employerclassified
FROM tblclassifieds c
LEFT JOIN tblclassifiedscategories clc ON c.categoryid = clc.id
LEFT JOIN ftblstates ON c.stateid = ftblstates.id
WHERE c.expirydate != '' AND c.expirydate >= '5/17/2011'
UNION ALL
SELECT ce.id, ce.name, ce.inserteddate, suburb AS cityname, ftblstates.name AS statename, ce.jobtype AS catname, ce.listingimagelogo, ce.orgname, '' AS relocateyn, '1' AS employerclassified
FROM tblclassifiedemployers ce
LEFT JOIN ftblstates ON ce.stateid = ftblstates.id
WHERE ce.expirydate != '' AND ce.expirydate >= '5/17/2011'
) a
ORDER BY inserteddate desc;
答案是否与下面类似?
SELECT TOP 10 * FROM (
SELECT c.id, c.name, c.inserteddate, c.cityname, ftblstates.name AS statename, clc.name AS catname, '' AS listingimagelogo, '' AS orgname, relocateyn, '' AS employerclassified
FROM tblclassifieds c
LEFT JOIN tblclassifiedscategories clc ON c.categoryid = clc.id
LEFT JOIN ftblstates ON c.stateid = ftblstates.id
WHERE c.expirydate != '' AND c.expirydate >= '5/17/2011'
UNION ALL
SELECT ce.id, ce.name, ce.inserteddate, suburb AS cityname, ftblstates.name AS statename, ce.jobtype AS catname, ce.listingimagelogo, ce.orgname, '' AS relocateyn, '1' AS employerclassified
FROM tblclassifiedemployers ce
LEFT JOIN ftblstates ON ce.stateid = ftblstates.id
WHERE ce.expirydate != '' AND ce.expirydate >= '5/17/2011'
) a
WHERE NOT a.id IN (SELECT TOP 10 tblclassifieds.id ...
ORDER BY inserteddate desc;
有人可以帮我完成查询吗?
I've got a SQLServer problem.
I'm trying to work out how to show a second page of results. The first page of results are pulled using the query below.
SELECT TOP 10 * FROM (
SELECT c.id, c.name, c.inserteddate, c.cityname, ftblstates.name AS statename, clc.name AS catname, '' AS listingimagelogo, '' AS orgname, relocateyn, '' AS employerclassified
FROM tblclassifieds c
LEFT JOIN tblclassifiedscategories clc ON c.categoryid = clc.id
LEFT JOIN ftblstates ON c.stateid = ftblstates.id
WHERE c.expirydate != '' AND c.expirydate >= '5/17/2011'
UNION ALL
SELECT ce.id, ce.name, ce.inserteddate, suburb AS cityname, ftblstates.name AS statename, ce.jobtype AS catname, ce.listingimagelogo, ce.orgname, '' AS relocateyn, '1' AS employerclassified
FROM tblclassifiedemployers ce
LEFT JOIN ftblstates ON ce.stateid = ftblstates.id
WHERE ce.expirydate != '' AND ce.expirydate >= '5/17/2011'
) a
ORDER BY inserteddate desc;
Is the answer similar to the following?
SELECT TOP 10 * FROM (
SELECT c.id, c.name, c.inserteddate, c.cityname, ftblstates.name AS statename, clc.name AS catname, '' AS listingimagelogo, '' AS orgname, relocateyn, '' AS employerclassified
FROM tblclassifieds c
LEFT JOIN tblclassifiedscategories clc ON c.categoryid = clc.id
LEFT JOIN ftblstates ON c.stateid = ftblstates.id
WHERE c.expirydate != '' AND c.expirydate >= '5/17/2011'
UNION ALL
SELECT ce.id, ce.name, ce.inserteddate, suburb AS cityname, ftblstates.name AS statename, ce.jobtype AS catname, ce.listingimagelogo, ce.orgname, '' AS relocateyn, '1' AS employerclassified
FROM tblclassifiedemployers ce
LEFT JOIN ftblstates ON ce.stateid = ftblstates.id
WHERE ce.expirydate != '' AND ce.expirydate >= '5/17/2011'
) a
WHERE NOT a.id IN (SELECT TOP 10 tblclassifieds.id ...
ORDER BY inserteddate desc;
Can someone please help me out completing the query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个简单的方法:
我没有改变你的内部查询。
编辑:在 where 子句中添加括号
A simple way of doing it:
I didnt alter your internal query.
Edit: Added parenteses in where clause