blob: 905000178845fa601529caa8f3c8783982878bb6 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
use tpch;
select element {'n_name':n_name,'revenue':revenue}
from Customer as c,
(
select element {'n_name':l1.n_name,'l_extendedprice':l1.l_extendedprice,'l_discount':l1.l_discount,'s_nationkey':l1.s_nationkey,'o_custkey':o.o_custkey}
from Orders as o,
(
select element {'n_name':s1.n_name,'l_extendedprice':l.l_extendedprice,'l_discount':l.l_discount,'l_orderkey':l.l_orderkey,'s_nationkey':s1.s_nationkey}
from LineItem as l,
(
select element {'n_name':n1.n_name,'s_suppkey':s.s_suppkey,'s_nationkey':s.s_nationkey}
from Supplier as s,
(
select element {'n_name':n.n_name,'n_nationkey':n.n_nationkey}
from Nation as n,
Region as r
where (n.n_regionkey = r.r_regionkey)
) as n1
where (s.s_nationkey = n1.n_nationkey)
) as s1
where (l.l_suppkey = s1.s_suppkey)
) as l1
where ((l1.l_orderkey = o.o_orderkey) and (o.o_orderdate >= '1990-01-01') and (o.o_orderdate < '1995-01-01'))
) as o1
where ((c.c_nationkey = o1.s_nationkey) and (c.c_custkey = o1.o_custkey))
/* +hash */
group by o1.n_name as n_name
with revenue as tpch.coll_sum((
select element (i.l_extendedprice * (1 - i.l_discount))
from o1 as i
))
order by revenue desc
;