File size: 489 Bytes
2eae90c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- $ID$
-- TPC-H/TPC-R Customer Distribution Query (Q13)
-- Variant A
-- Approved March 1998
:x
create view orders_per_cust:s (custkey, ordercount) as
	select
		c_custkey,
		count(o_orderkey)
	from
		customer left outer join orders on
			c_custkey = o_custkey
			and o_comment not like '%:1%:2%'
	group by
		c_custkey;

:o
select
	ordercount,
	count(*) as custdist
from
	orders_per_cust:s
group by
	ordercount
order by
	custdist desc,
	ordercount desc;

drop view orders_per_cust:s;
:n -1