クエリ1件の結果:340万行のSQL Server接続87行の
SELECT
MIN(LEFT(Date_Last_Updated, 4)) AS Year_of_Transfer,
MIN(RIGHT(LEFT(Date_Last_Updated, 6), 2)) AS Month_of_Transfer,
MIN(RIGHT(LEFT(Date_Last_Updated, 8), 2)) AS Day_of_Transfer,
CRS, Loan_Code,
MIN(Date_Last_Updated) AS Min_Date_Last_Updated
FROM
dbo.Transfer_Final_Accounts_CO_SH
WHERE
(LEFT(Date_Last_Updated, 4) >= '2016')
AND (Subcategory = 'Transfer to Workout')
GROUP BY
CRS, Loan_Code
ORDER BY
Loan_Code
クエリ検索結果:
SELECT
Date_Last_Updated,
SUM(NPL_Amount_Last_Quarter) AS NPL_Amount_Last_Quarter,
Loan_Code,
SUM([Total_Balance_€]) AS Total_Balance,
SUM(On_Balance_Amount_Last_Quarter) AS On_Balance_Last_Q,
SUM([Off_Balance_Amount_€]) AS Off_Balance_Last_Q, CRS,
[On_Balance_Amount_€], [Off_Balance_Amount_€], [Total_Balance_€],
NPL_Amount_Last_Quarter AS NPL_Amount_Last_Q,
[NPL_Amount_€], On_Balance_Amount_Last_Quarter,
Material_Bucket, Material_Bucket_Last_Quarter
FROM
dbo.Transfer_Final_Accounts_COM_WORK
GROUP BY
CRS, Date_Last_Updated, Loan_Code, [On_Balance_Amount_€],
[Off_Balance_Amount_€], [Total_Balance_€], NPL_Amount_Last_Quarter,
[NPL_Amount_€], On_Balance_Amount_Last_Quarter, Material_Bucket,
Material_Bucket_Last_Quarter
クエリ3は2の上方及び0の行の結果を結ぶ:
SELECT
dbo.Transfer_to_Workout_Total_Balances.Total_Balance,
dbo.Transfer_to_Workout_Total_Balances.On_Balance_Last_Q,
dbo.Transfer_to_Workout_Total_Balances.Off_Balance_Last_Q,
dbo.Transfer_to_Workout_Total_Balances.NPL_Amount_Last_Quarter,
dbo.Transfer_to_workout_min_dates.Year_of_Transfer,
dbo.Transfer_to_workout_min_dates.Month_of_Transfer,
dbo.Transfer_to_workout_min_dates.Day_of_Transfer,
dbo.Transfer_to_workout_min_dates.CRS AS Expr1,
dbo.Transfer_to_workout_min_dates.Loan_Code AS Expr2,
dbo.Transfer_to_workout_min_dates.Min_Date_Last_Updated,
dbo.Transfer_to_Workout_Total_Balances.[On_Balance_Amount_€],
dbo.Transfer_to_Workout_Total_Balances.[Off_Balance_Amount_€],
dbo.Transfer_to_Workout_Total_Balances.[Total_Balance_€],
dbo.Transfer_to_Workout_Total_Balances.[NPL_Amount_€],
dbo.Transfer_to_Workout_Total_Balances.NPL_Amount_Last_Q,
dbo.Transfer_to_Workout_Total_Balances.On_Balance_Amount_Last_Quarter,
dbo.Transfer_to_Workout_Total_Balances.Material_Bucket,
dbo.Transfer_to_Workout_Total_Balances.Material_Bucket_Last_Quarter
FROM
dbo.Transfer_to_workout_min_dates
INNER JOIN
dbo.Transfer_to_Workout_Total_Balances ON dbo.Transfer_to_workout_min_dates.Loan_Code = dbo.Transfer_to_Workout_Total_Balances.Loan_Code
AND dbo.Transfer_to_workout_min_dates.Min_Date_Last_Updated = dbo.Transfer_to_Workout_Total_Balances.Date_Last_Updated
なぜ私は上記の結果をとらないのですか?
3番目のクエリはどのように最初の2つに「接続」しますか?これらの3つのすべてはお互いに大きく異なって見えます。 – David
どのようにクエリが接続されていますか?両方のクエリはグループ化された結果を返しますが、クエリ3は 'GROUP BY'節を持ちません。 –
btwテーブルのエイリアス名を使用できます。 '... FROM dbo.Transfer_to_workout_min_dates AS min_dates ...' –