Databases Reference
In-Depth Information
 Bild 24.4■
Häuigkeitsverteilung der durchschnittlichen
Retourenquote
Schauen Sie sich den oberen Befehl einmal genauer an.
WHEN 4 THEN '4 bis 5'
WHEN 5 THEN '4 bis 5'
In beiden Fällen wird der Datensatz der Gruppe '4 bis 5' zugeordnet.
Select rta.Artikel, AVG(rta.RQ_Artikel)avg_Retourenquote,
COUNT (*) Häufigkeit
from
(Select ord.Bestellung,
CASE ord.Artikel WHEN 1 THEN '1' WHEN 2 THEN '2' WHEN 3 THEN '3'
WHEN 4 THEN '4 bis 5' WHEN 5 THEN '4 bis 5' Else '6 und mehr' END Artikel,
isnull (ret.Artikelretouren,0)Artikelretouren,
CAST (isnull (ret.Artikelretouren,0)/ord.Artikel*100 as DECIMAL(10,2)) RQ_Ar-
tikel
from
(SELECT s.orderNo Bestellung,
cast (sum (s.quantity)as DECIMAL(10,0))Artikel
from [dbo].[iw_sales]s
where s.type = 2
and s.quantity > 0
and s.orderDate between '01.04.2011' and '30.06.2011'
group by s.orderNo)ord
Left OUTER JOIN
(SELECT rh.orderNo Bestellung,
cast(sum( rl.quantity)as DECIMAL(10,0)) Artikelretouren
FROM
[dbo].[iw_sales]s,[dbo].[iw_return_line]rl,
[dbo].[iw_return_header]rh
where s.type = 2
and s.orderNo = rh.orderNo
and rh.returnNo = rl.returnNo
and s.IWAN = rl.IWAN
 
Search WWH ::




Custom Search