I 3 Tabellen habe hat unterWie dieser Server in SQL zur Abfrage
tbMaster
Branch_code Sale_No Amount Type_Code
-------------------------------------
0 1222 421.00 9
0 1227 323.00 9
0 1228 1186.00 9
0 1223 119.00 2
gezeigt und
tType
Type_Code Type_Name
1 NTB
2 TABLE SERVICE
3 A/C TABLE SERVICE
4 TAKE AWAY
5 CAR SERVICE
6 HOME DELIVERY
7 SELF SERVICE
und schließlich
tFree
Type_Code Branch_code Amount
-----------------------------------
1 0 261.00
1 0 112.20
1 0 336.60
Jetzt bekomme ich die Ausgabe als sagen zum Beispiel
Branch_code TypeTcount SaleValue Type_Name
NULL 0 0.00 NTB
0 1 910.00 TABLE SERVICE
NULL 0 0.00 A/C TABLE SERVICE
NULL 0 0.00 TAKE AWAY
NULL 0 0.00 CAR SERVICE
NULL 0 0.00 HOME DELIVERY
NULL 0 0.00 SELF SERVICE
Jetzt
meine Frage ist
SELECT
sm.Branch_code,
COUNT(sm.Sale_No) TypeTcount,
ISNULL(SUM(sm.Amount), 0) SaleValue,
t.Type_Name
FROM [tMaster] sm
RIGHT JOIN [tType] t
ON sm.Type_Code = t.Type_Code
AND sm.Branch_code = 0
GROUP BY
t.Type_Name,
t.Type_Code
ORDER BY t.Type_Code
Aber ich möchte die Anzahl der Type_code
aus der Tabelle tFree
in der Ausgabe TypeTCount
erhalten.
Erwartetes Ergebnis:
Branch_code TypeTcount SaleValue Type_Name
NULL 3 709.80 NTB
0 1 910.00 TABLE SERVICE
NULL 0 0.00 A/C TABLE SERVICE
NULL 0 0.00 TAKE AWAY
NULL 0 0.00 CAR SERVICE
NULL 0 0.00 HOME DELIVERY
NULL 0 0.00 SELF SERVICE
Nur zeigen die tFree
Tabellensätze in der Nähe von NTB
Bitte veröffentlichen Sie das erwartete Ergebnis. –