嘗試使用CROSS APPLY而不是OFFSET FETCH並一次完成。我抓住TOP 2向你展示你可以抓住任意數量的行。
IF OBJECT_ID('tempdb..#tblPhoneNumber') IS NOT NULL
DROP TABLE #tblPhoneNumber;
IF OBJECT_ID('tempdb..#Country') IS NOT NULL
DROP TABLE #Country;
CREATE TABLE #tblPhoneNumber (ID INT, Country VARCHAR(100), PhoneNumber INT);
CREATE TABLE #Country (Country VARCHAR(100));
INSERT INTO #Country
VALUES ('USA'),('UK');
INSERT INTO #tblPhoneNumber
VALUES (1,'USA',11111),
(2,'USA',22222),
(3,'USA',33333),
(4,'UK',44444),
(5,'UK',55555),
(6,'UK',66666);
SELECT *
FROM #Country
CROSS APPLY(
SELECT TOP (2) ID,Country,PhoneNumber --Just change to TOP(50) for your code
FROM #tblPhoneNumber
WHERE #Country.Country = #tblPhoneNumber.Country
) CA
爲什麼你只能分批閱讀50份?你能使每批次的行數更高嗎? – Stephan
是的!但我想讀50 50!例如來自美國的50個數字,來自印度的50個數字...... – mohammad
所以你想爲每個國家選擇50行。一次完成所有事情都可以嗎? – Stephan