blob: 2a490d96ba786e09e3ab8e7cdaa42f3e5c505614 [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;
set import-private-functions 'true';
for $gco in (
for $co in (
for $c in dataset('Customer')
return {
"c_custkey": $c.c_custkey,
"o_orderkey_count": count(
for $o in dataset('Orders')
where $c.c_custkey = $o.o_custkey and not(like($o.o_comment,'%special%requests%'))
return $o.o_orderkey
)
}
)
group by $c_custkey := $co.c_custkey with $co
return {
"c_custkey": $c_custkey,
"c_count": sum(for $i in $co return $i.o_orderkey_count)
}
)
group by $c_count := $gco.c_count with $gco
let $custdist := count($gco)
order by $custdist desc, $c_count desc
return {
"c_count": $c_count,
"custdist": $custdist
}