0

如何使以下语句将第 100 行提取到第 200 行:

SELECT Offices.OfficeID, ContractsBooksCommodities.CommodityID
  FROM ((((Offices 
    INNER JOIN tbl_Sales ON Offices.CompanyID = tbl_Sales.CompanyID) 
    INNER JOIN ContractBooks ON tbl_Sales.CompanyID = ContractBooks.CompanyID)      
    INNER JOIN ContractsBooksAds ON ContractBooks.ContractNum = ContractsBooksAds.ContractNum) 
    INNER JOIN ContractsBooksBrands ON ContractsBooksAds.ContractNum = ContractsBooksBrands.ContractNum) 
    INNER JOIN ContractsBooksCommodities ON ContractsBooksBrands.ContractNum = ContractsBooksCommodities.ContractNum;
4

1 回答 1

0

这可能很慢:

SELECT Top 101 Offices.OfficeID, ContractsBooksCommodities.CommodityID
  FROM ((((Offices 
    INNER JOIN tbl_Sales ON Offices.CompanyID = tbl_Sales.CompanyID) 
    INNER JOIN ContractBooks ON tbl_Sales.CompanyID = ContractBooks.CompanyID)      
    INNER JOIN ContractsBooksAds ON ContractBooks.ContractNum = ContractsBooksAds.ContractNum) 
    INNER JOIN ContractsBooksBrands ON ContractsBooksAds.ContractNum = ContractsBooksBrands.ContractNum) 
    INNER JOIN ContractsBooksCommodities ON ContractsBooksBrands.ContractNum = ContractsBooksCommodities.ContractNum
WHERE Offices.OfficeID NOT IN (SELECT Top 99 Offices.OfficeID
  FROM ((((Offices 
    INNER JOIN tbl_Sales ON Offices.CompanyID = tbl_Sales.CompanyID) 
    INNER JOIN ContractBooks ON tbl_Sales.CompanyID = ContractBooks.CompanyID)      
    INNER JOIN ContractsBooksAds ON ContractBooks.ContractNum = ContractsBooksAds.ContractNum) 
    INNER JOIN ContractsBooksBrands ON ContractsBooksAds.ContractNum = ContractsBooksBrands.ContractNum) 
    INNER JOIN ContractsBooksCommodities ON ContractsBooksBrands.ContractNum = ContractsBooksCommodities.ContractNum
ORDER BY Offices.OfficeID, ContractsBooksCommodities.CommodityID) 
ORDER BY Offices.OfficeID, ContractsBooksCommodities.CommodityID

我不知道哪些字段使您的排序独一无二,但这正是您所需要的,因为 MS Access 将返回匹配项。

于 2013-02-15T00:12:05.273 回答