Databases Reference
In-Depth Information
Der komplette Select wird in Klammern gesetzt und mit einem Alias bezeichnet. Wir nen-
nen ihn bigSB für Big-Shopping-Basket. Ausgegeben werden alle Artikel und die Anzahl
aller vorhandenen Kombinationen. Der Count -Befehl erzwingt eine Group by -Klausel am
Schluss. Die Kombination mit der höchsten Anzahl wird durch die Order by -Klausel order
by Anzahl desc nach oben gesetzt.
Select bigSB.Artikel_1, bigSB.Artikel_2, bigSB.Artikel_3, bigSB.
Artikel_4,COUNT (*)Anzahl
from
(Select distinct sb1.orderNo,
sb1.[description]Artikel_1,sb1.colorDescription Color_1,
sb1.size Size_1, sb1.productGroup Group_1,
sb2.[description]Artikel_2,sb2.colorDescription Color_2,
sb2.size Size_2, sb2.productGroup Group_2,
sb3.[description]Artikel_3,sb3.colorDescription Color_3,
sb3.size Size_3, sb3.productGroup Group_3,
sb4.[description]Artikel_4,sb4.colorDescription Color_4,
sb4.size Size_4, sb4.productGroup Group_4
from
(SELECT s.[line_No], s.[orderNo], a.article_No, a.[description],
a.colorDescription, a.size, a.productGroup
FROM [dbo].[iw_sales]s,[dbo].[iw_article]a
where s.[type] = 2
and s.line_No = 1
and s.orderDate between '01.05.2011'and '31.05.2011'
and s.IWAN = a.IWAN)sb1
left outer join
(SELECT s.[line_No], s.[orderNo], a.article_No, a.[description],
a.colorDescription, a.size, a.productGroup
FROM [dbo].[iw_sales]s,[dbo].[iw_article]a
where s.[type] = 2
and s.line_No = 2
and s.orderDate between '01.05.2011'and '31.05.2011'
and s.IWAN = a.IWAN)sb2
on sb1.orderNo = sb2.orderNo
left outer join
(SELECT s.[line_No], s.[orderNo], a.article_No, a.[description],
a.colorDescription, a.size, a.productGroup
FROM [dbo].[iw_sales]s,[dbo].[iw_article]a
where s.[type] = 2
and s.line_No = 3
and s.orderDate between '01.05.2011'and '31.05.2011'
and s.IWAN = a.IWAN)sb3
on sb1.orderNo = sb3.orderNo
left outer join
(SELECT s.[line_No], s.[orderNo], a.article_No, a.[description],
a.colorDescription, a.size, a.productGroup
FROM [dbo].[iw_sales]s,[dbo].[iw_article]a
where s.[type] = 2
and s.line_No = 4
and s.orderDate between '01.05.2011'and '31.05.2011'
and s.IWAN = a.IWAN)sb4
on sb1.orderNo = sb4.orderNo)bigSB
group by bigSB.Artikel_1, bigSB.Artikel_2, bigSB.Artikel_3, bigSB.Artikel_4
order by Anzahl desc
 
Search WWH ::




Custom Search