blob: 14e87db2cdaaa985bbe01a36a5aeb9d29017ebf5 [file] [log] [blame]
buyingyicf48fb52012-11-02 00:31:31 +00001-- create the tables and load the data
2create external table lineitem (L_ORDERKEY INT, L_PARTKEY INT, L_SUPPKEY INT, L_LINENUMBER INT, L_QUANTITY DOUBLE, L_EXTENDEDPRICE DOUBLE, L_DISCOUNT DOUBLE, L_TAX DOUBLE, L_RETURNFLAG STRING, L_LINESTATUS STRING, L_SHIPDATE STRING, L_COMMITDATE STRING, L_RECEIPTDATE STRING, L_SHIPINSTRUCT STRING, L_SHIPMODE STRING, L_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/100/lineitem';
3create external table part (P_PARTKEY INT, P_NAME STRING, P_MFGR STRING, P_BRAND STRING, P_TYPE STRING, P_SIZE INT, P_CONTAINER STRING, P_RETAILPRICE DOUBLE, P_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/100/part';
4
5-- create the result table
6create table q17_small_quantity_order_revenue (avg_yearly double);
7create table lineitem_tmp (t_partkey int, t_avg_quantity double);
8
9-- the query
10insert overwrite table lineitem_tmp
11select
12 l_partkey as t_partkey, 0.2 * avg(l_quantity) as t_avg_quantity
13from
14 lineitem
15group by l_partkey;
16
17insert overwrite table q17_small_quantity_order_revenue
18select
19 sum(l_extendedprice) / 7.0 as avg_yearly
20from
21 (select l_quantity, l_extendedprice, t_avg_quantity from
22 lineitem_tmp t join
23 (select
24 l_quantity, l_partkey, l_extendedprice
25 from
26 part p join lineitem l
27 on
28 p.p_partkey = l.l_partkey
29 and p.p_brand = 'Brand#23'
30 and p.p_container = 'MED BOX'
31 ) l1 on l1.l_partkey = t.t_partkey
32 ) a
33where l_quantity < t_avg_quantity;
34
35DROP TABLE lineitem;
36DROP TABLE part;
37DROP TABLE q17_small_quantity_order_revenue;
38DROP TABLE lineitem_tmp;