blob: ede220ffbf61efb2dd965f4c5c1f01dc13f940fd [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 dataverse tpch;
for $locn in (
for $l in dataset('LineItem')
for $ocn in (
for $o in dataset('Orders')
for $c in dataset('Customer')
where $c.c_custkey = $o.o_custkey and $o.o_orderdate >= '1993-10-01'
and $o.o_orderdate < '1994-01-01'
for $n in dataset('Nation')
where $c.c_nationkey = $n.n_nationkey
return {
"c_custkey": $c.c_custkey,
"c_name": $c.c_name,
"c_acctbal": $c.c_acctbal,
"n_name": $n.n_name,
"c_address": $c.c_address,
"c_phone": $c.c_phone,
"c_comment": $c.c_comment,
"o_orderkey": $o.o_orderkey
}
)
where $l.l_orderkey = $ocn.o_orderkey and $l.l_returnflag = 'R'
return {
"c_custkey": $ocn.c_custkey,
"c_name": $ocn.c_name,
"c_acctbal": $ocn.c_acctbal,
"n_name": $ocn.n_name,
"c_address": $ocn.c_address,
"c_phone": $ocn.c_phone,
"c_comment": $ocn.c_comment,
"l_extendedprice": $l.l_extendedprice,
"l_discount": $l.l_discount
}
)
group by $c_custkey:=$locn.c_custkey,
$c_name:=$locn.c_name,
$c_acctbal:=$locn.c_acctbal, $c_phone:=$locn.c_phone,
$n_name:=$locn.n_name, $c_address:=$locn.c_address, $c_comment:=$locn.c_comment
with $locn
let $revenue := sum(for $i in $locn return $i.l_extendedprice * (1 - $i.l_discount))
order by $revenue desc
limit 20
return {
"c_custkey": $c_custkey,
"c_name": $c_name,
"revenue": $revenue,
"c_acctbal": $c_acctbal,
"n_name": $n_name,
"c_address": $c_address,
"c_phone": $c_phone,
"c_comment": $c_comment
}