我有這個SELECT DISTINCT
SQL查詢,我想實現在TotalPaidPerEvent
列將總和k.akce = q.akce AND z.kod - q.zpro
總和,其中條件 - 多部分組成的標識符「t.column」無法綁定
我試過OUTER APPLY
但它似乎是獲得每個z.kod
相同的SUM。所有我想要實現的是,這將是獨一無二的計數k.akce = q.akce AND z.kod = q.zpro
SELECT DISTINCT
k.akce,
z.firma,
z.osoba,
z.kod,
qnt.TotalPaidPerEvent
FROM zprost z
OUTER APPLY (
SELECT SUM(q.zaplac) AS TotalPaidPerEvent
FROM klient q
WHERE z.kod = q.zpro
) qnt
LEFT JOIN klient k
ON k.zpro = z.kod
WHERE rocnik = 2014;
當我嘗試這樣做: 任何有助於實現這一目標?
OUTER APPLY (SELECT SUM(q.zaplac) AS TotalPaidPerEvent FROM klient q WHERE z.kod=q.zpro AND k.akce = q.akce) qnt
我得到以下信息:
The multi-part identifier 'k.akce' could not be bound.
預先感謝您的時間。
你能添加顯示錯誤,並且表架構完整的查詢? – Tanner
Re。錯誤:您需要在引用'outer apply'之前加入'k(即klient)' –