多表关联查询加内联形式收藏
在多表关联的情况下,其中内联的表结果由外联方式产生并继续过滤
代码
SELECT MAX(A.CityID) AS CityID,SUM(StockInfo.HaveRate) AS HaveRate,ProvinceName,COUNT(StockholderID) AS PerCount
FROM(
SELECT TOP 50 StockholderID,HaveRate,CityID,ProvinceName from (
SELECT TOP 50 Stockholder.StockholderID,HaveRate,Stockholder.CityID,
IIF(a.ProvinceName<> '',a.ProvinceName,'其他') AS ProvinceName
FROM StockInfo,CapitalStock,
(select Stockholder.StockholderID,ProvinceName,Stockholder.CityID from
(Stockholder LEFT JOIN AreaInfo ON AreaInfo.CityID = Stockholder.CityID)
) as a
where a.StockholderID = StockInfo.StockholderID
AND CapitalStock.CapitalStockID = StockInfo.CapitalStockID
AND CapitalStock.InputTime =#2010-05-28# ORDER BY HaveNum DESC
)
) AS A GROUP BY ProvinceName
FROM(
SELECT TOP 50 StockholderID,HaveRate,CityID,ProvinceName from (
SELECT TOP 50 Stockholder.StockholderID,HaveRate,Stockholder.CityID,
IIF(a.ProvinceName<> '',a.ProvinceName,'其他') AS ProvinceName
FROM StockInfo,CapitalStock,
(select Stockholder.StockholderID,ProvinceName,Stockholder.CityID from
(Stockholder LEFT JOIN AreaInfo ON AreaInfo.CityID = Stockholder.CityID)
) as a
where a.StockholderID = StockInfo.StockholderID
AND CapitalStock.CapitalStockID = StockInfo.CapitalStockID
AND CapitalStock.InputTime =#2010-05-28# ORDER BY HaveNum DESC
)
) AS A GROUP BY ProvinceName