程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> sql server-sqlserver2000復雜語句分頁

sql server-sqlserver2000復雜語句分頁

編輯:編程綜合問答
sqlserver2000復雜語句分頁

倒霉得很,公司的數據庫是2000的,rownumber用不了,WITH AS用不了,查詢條件還慢復雜,想了蠻久,沒啥辦法了,求助下。下面是最簡單的一條sql:
SELECT a.autoid,a.callerid,a.doorid,a.cardday,a.eventtype
FROM Cr_CardEvent a, Cr_Caller_BasicInfo b
WHERE a.callerid = b.callerid AND b.callertype = 1
AND a.cardday BETWEEN '2011-09-01' AND '2011-09-02'
拋磚引玉...
下面這條是上面的小小升級版
SELECT c.autoid,c.callerid,c.cardid,c.doorid,c.cardday,c.eventtype,d.doorid AS max_doorId,d.eventType AS max_eventSort,d.cardday AS max_cardDay
FROM (SELECT * FROM cr_cardevent a WHERE EXISTS (SELECT 1 FROM(SELECT MIN(cardday)min_time ,callerid FROM cr_cardevent c,Com_EmpCard card
WHERE cardday BETWEEN '2014-09-01' AND '2014-10-01' AND c.cardid=card.cardid AND EXISTS
(SELECT 1 FROM Finger_Data fingure where fingure.cardid=card.cardid) GROUP BY convert(varchar(10),cardday,121), callerid)b
WHERE a.cardday=b.min_time AND a.callerid=b.callerid ))c ,(SELECT * FROM cr_cardevent a WHERE EXISTS
(SELECT 1 FROM(SELECT max(cardday)min_time ,callerid
FROM cr_cardevent c,Com_EmpCard card where cardday BETWEEN '2014-09-01' AND '2014-10-01' AND c.cardid=card.cardid GROUP BY convert(varchar(10),cardday,121), callerid)b WHERE a.cardday=b.min_time AND a.callerid=b.callerid))d,cr_caller_basicinfo e
WHERE c.callerid = d.callerid AND c.callerid = e.callerid AND e.callertype=1
AND 0=DATEDIFF(DAY, convert(varchar(10),c.cardday,121),convert(varchar(10),d.cardday,121))

最佳回答:


最後用的游標解決問題。在這種rownumber函數和CTE沒法用並且限制頗多(權限)的sqlserver2000,只能用了游標去分頁

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved