|
ALTER TABLE ORDERS
ADD PRIMARY KEY (O_ORDERKEY);
-- For table PARTSUPP
ALTER TABLE PARTSUPP
ADD FOREIGN KEY PARTSUPP_FK1 (PS_SUPPKEY) references SUPPLIER;
ALTER TABLE PARTSUPP
ADD CONSTRAINT PARTSUPP_FK2 FOREIGN KEY (PS_PARTKEY) references PART;
-- For table ORDERS
ALTER TABLE ORDERS
ADD CONSTRAINT ORDERS_FK1 FOREIGN KEY (O_CUSTKEY) references CUSTOMER;
-- For table LINEITEM
ALTER TABLE LINEITEM
ADD CONSTRAINT LINEITEM_FK1 FOREIGN KEY (L_ORDERKEY) references ORDERS;
ALTER TABLE LINEITEM
ADD CONSTRAINT LINEITEM_FK2 FOREIGN KEY (L_PARTKEY,L_SUPPKEY) references
PARTSUPP;
-- For table PART
ALTER TABLE PART
ADD PRIMARY KEY (P_PARTKEY);
time used: 14210.697(ms).
SQL>SQL>SQL>SQL>2 3 -- For table SUPPLIER
ALTER TABLE SUPPLIER
ADD PRIMARY KEY (S_SUPPKEY);
time used: 691.154(ms).
SQL>SQL>2 ALTER TABLE SUPPLIER
ADD CONSTRAINT SUPPLIER_FK1 FOREIGN KEY (S_NATIONKEY) references NATION;
time used: 193.020(ms).
SQL>SQL>SQL>SQL>2 3
-- For table PARTSUPP
ALTER TABLE PARTSUPP
ADD PRIMARY KEY (PS_PARTKEY,PS_SUPPKEY);
time used: 87118.346(ms).
SQL>SQL>SQL>SQL>2 3 -- For table CUSTOMER
ALTER TABLE CUSTOMER
ADD PRIMARY KEY (C_CUSTKEY);
time used: 12403.566(ms).
SQL>SQL>2 ALTER TABLE CUSTOMER
ADD CONSTRAINT CUSTOMER_FK1 FOREIGN KEY (C_NATIONKEY) references NATION;
time used: 3210.720(ms).
SQL>SQL>SQL>SQL>2 3
-- For table LINEITEM
ALTER TABLE LINEITEM
ADD PRIMARY KEY (L_ORDERKEY,L_LINENUMBER);
time used: 543594.582(ms).
SQL>SQL>SQL>SQL>2 3 -- For table ORDERS
ALTER TABLE ORDERS
ADD PRIMARY KEY (O_ORDERKEY);
time used: 120313.765(ms).
SQL>SQL>SQL>SQL>2 3 第3行: 'PARTSUPP_FK1'附近有语法错误
SQL>SQL>SQL>SQL>2 ALTER TABLE PARTSUPP
ADD CONSTRAINT PARTSUPP_FK2 FOREIGN KEY (PS_PARTKEY) references PART;
time used: 40301.053(ms).
SQL>SQL>SQL>SQL>2 3 -- For table ORDERS
ALTER TABLE ORDERS
ADD CONSTRAINT ORDERS_FK1 FOREIGN KEY (O_CUSTKEY) references CUSTOMER;
time used: 106137.191(ms).
SQL>SQL>SQL>SQL>2 3 -- For table LINEITEM
ALTER TABLE LINEITEM
ADD CONSTRAINT LINEITEM_FK1 FOREIGN KEY (L_ORDERKEY) references ORDERS;
time used: 341882.766(ms).
SQL>SQL>SQL>SQL>2 3 ALTER TABLE LINEITEM
ADD CONSTRAINT LINEITEM_FK2 FOREIGN KEY (L_PARTKEY,L_SUPPKEY) references
PARTSUPP;
time used: 563711.689(ms).
SQL>SQL>SQL>SQL>SQL>SQL>SQL>SQL>SQL>
SQL>
SQL>
SQL>select
2 l_returnflag,
3 l_linestatus,
4 sum(l_quantity) as sum_qty,
5 sum(l_extendedprice) as sum_base_price,
6 sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
7 sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
avg(l_quantity) as avg_qty,
avg(l_extendedprice) as avg_price,
8 9 10 avg(l_discount) as avg_disc,
11 count(*) as count_order
12 from
13 lineitem
14 where
15 l_shipdate <= date '1998-12-01' - interval '109' day (3)
16 group by
17 l_returnflag,
18 l_linestatus
19 order by
20 l_returnflag,
21 l_linestatus
22 limit 100;
select
l_returnflag,
l_linestatus,
sum(l_quantity) as sum_qty,
sum(l_extendedprice) as sum_base_price,
sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
avg(l_quantity) as avg_qty,
avg(l_extendedprice) as avg_price,
avg(l_discount) as avg_disc,
count(*) as count_order
from
lineitem
where
l_shipdate <= date '1998-12-01' - interval '109' day (3)
group by
l_returnflag,
l_linestatus
order by
l_returnflag,
l_linestatus
limit 100;
l_returnflag l_linestatus sum_qty sum_base_price sum_disc_price sum_chargeavg_qty avg_price avg_disc count_order
1 A F 377518399.00 566065727797.25 537759104278.0656 559276670892.116819 25.500975 38237.151009.050007 14804077
2 N F 9851614.00 14767438399.17 14028805792.2114 14590490998.366737 25.522448 38257.810660.049973 385998
3 N O 733123780.00 1099304906498.07 1044335077295.6306 1086120726300.933136 25.497525 38233.044635 .049999 28752743
4 R F 377732830.00 566431054976.00 538110922664.7677 559634780885.086257 25.508385 38251.219274.049997 14808183
4 rows got
time used: 399240.725(ms).
SQL>SQL>select
2 s_acctbal,
3 s_name,
4 n_name,
5 p_partkey,
6 p_mfgr,
7 s_address,
8 s_phone,
9 s_comment
10 from
11 part,
12 supplier,
13 partsupp,
nation,
14 15 region
16 where
17 p_partkey = ps_partkey
18 and s_suppkey = ps_suppkey
19 and p_size = 33
20 and p_type like '%STEEL'
21 and s_nationkey = n_nationkey
22 and n_regionkey = r_regionkey
23 and r_name = 'MIDDLE EAST'
24 and ps_supplycost = (
25 select
26 min(ps_supplycost)
27 from
28 partsupp,
29 supplier,
30 nation,
31 region
32 where
33 p_partkey = ps_partkey
34 and s_suppkey = ps_suppkey
35 and s_nationkey = n_nationkey
36 and n_regionkey = r_regionkey
37 and r_name = 'MIDDLE EAST'
38 )
39 order by
40 s_acctbal desc,
41 n_name,
42 s_name,
43 p_partkey
44 limit 100;
select
s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
from
part,
supplier,
partsupp,
nation,
region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and p_size = 33
and p_type like '%STEEL'
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'MIDDLE EAST'
and ps_supplycost = (
select
min(ps_supplycost)
from
partsupp,
supplier,
nation,
region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'MIDDLE EAST'
)
order by
s_acctbal desc,
n_name,
s_name,
p_partkey
limit 100;
s_acctbal s_name n_name p_partkey p_mfgr s_address s_phone s_comment
1 9999.21 Supplier#000081559 IRAQ 756551 Manufacturer#1 YplAwJxhoHNeIyqDv3kgzv x2dymRYx 21-345-604-7861 bold packages cajole blithely pinto beans. carefully special
2 9994.67 Supplier#000048146 EGYPT 1573100 Manufacturer#4 uq4pbng1m ,bHziSHWDqTi0mOSiqCn 14-860-865-5070 iously bold excuses x-ray evenly. even, regular accounts are daringly. even, ironic pack
3 9994.10 Supplier#000047385 SAUDI ARABIA 722377 Manufacturer#3 pbRKuJaBXBl,5bOv9UhB8SDR cuz 8 30-427-545-5707 nic dependencies nag fluffily across the blithely special foxes. furiously silent deposit
100 9779.57 Supplier#000021383 IRAQ 921382 Manufacturer#1 rE8nHb9QvK 21-316-417-2980 efully final braids beneath the carefully pending packages haggle blithel
100 rows got
time used: 191207.250(ms).
SQL>SQL> |
|