github.com/apache/beam/sdks/v2@v2.48.2/java/testing/tpcds/src/main/resources/queries/query39b.sql (about) 1 -- Licensed to the Apache Software Foundation (ASF) under one 2 -- or more contributor license agreements. See the NOTICE file 3 -- distributed with this work for additional information 4 -- regarding copyright ownership. The ASF licenses this file 5 -- to you under the Apache License, Version 2.0 (the 6 -- "License"); you may not use this file except in compliance 7 -- with the License. You may obtain a copy of the License at 8 -- 9 -- http://www.apache.org/licenses/LICENSE-2.0 10 -- 11 -- Unless required by applicable law or agreed to in writing, software 12 -- distributed under the License is distributed on an "AS IS" BASIS, 13 -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 -- See the License for the specific language governing permissions and 15 -- limitations under the License. 16 17 with inv as 18 (select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy 19 ,stdev,mean, case mean when 0 then null else stdev/mean end cov 20 from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy 21 ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean 22 from inventory 23 ,item 24 ,warehouse 25 ,date_dim 26 where inv_item_sk = i_item_sk 27 and inv_warehouse_sk = w_warehouse_sk 28 and inv_date_sk = d_date_sk 29 and d_year =1999 30 group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo 31 where case mean when 0 then 0 else stdev/mean end > 1) 32 select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov 33 ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov 34 from inv inv1,inv inv2 35 where inv1.i_item_sk = inv2.i_item_sk 36 and inv1.w_warehouse_sk = inv2.w_warehouse_sk 37 and inv1.d_moy=4 38 and inv2.d_moy=4+1 39 and inv1.cov > 1.5 40 order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov 41 ,inv2.d_moy,inv2.mean, inv2.cov