| /* |
| * 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 {'s_name':t4.s_name,'s_address':t4.s_address} |
| from ( |
| select distinct element {'ps_suppkey':pst1.ps_suppkey} |
| from ( |
| select element {'l_partkey':l_partkey,'l_suppkey':l_suppkey,'sum_quantity':(0.5 * STRICT_SUM(( |
| select element i.l_quantity |
| from (from g select value l) as i |
| )))} |
| from LineItem as l |
| group by l.l_partkey as l_partkey,l.l_suppkey as l_suppkey |
| group as g |
| ) as t2, |
| ( |
| select element {'ps_suppkey':ps.ps_suppkey,'ps_partkey':ps.ps_partkey,'ps_availqty':ps.ps_availqty} |
| from Partsupp as ps, |
| ( |
| select distinct element {'p_partkey':p.p_partkey} |
| from Part as p |
| ) as t1 |
| where (ps.ps_partkey = t1.p_partkey) |
| ) as pst1 |
| where ((pst1.ps_partkey = t2.l_partkey) and (pst1.ps_suppkey = t2.l_suppkey) and (pst1.ps_availqty > t2.sum_quantity)) |
| ) as t3, |
| ( |
| select element {'s_name':s.s_name,'s_address':s.s_address,'s_suppkey':s.s_suppkey} |
| from Nation as n, |
| Supplier as s |
| where (s.s_nationkey = n.n_nationkey) |
| ) as t4 |
| where (t3.ps_suppkey = t4.s_suppkey) |
| order by t4.s_name |
| ; |