github.com/apache/beam/sdks/v2@v2.48.2/java/testing/tpcds/src/main/resources/queries/query24b.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 ssales as
    18   (select c_last_name, c_first_name, s_store_name, ca_state, s_state, i_color,
    19           i_current_price, i_manager_id, i_units, i_size, sum(ss_net_paid) netpaid
    20   from store_sales, store_returns, store, item, customer, customer_address
    21   where ss_ticket_number = sr_ticket_number
    22     and ss_item_sk = sr_item_sk
    23     and ss_customer_sk = c_customer_sk
    24     and ss_item_sk = i_item_sk
    25     and ss_store_sk = s_store_sk
    26     and c_birth_country = upper(ca_country)
    27     and s_zip = ca_zip
    28     and s_market_id = 8
    29   group by c_last_name, c_first_name, s_store_name, ca_state, s_state,
    30            i_color, i_current_price, i_manager_id, i_units, i_size)
    31   select c_last_name, c_first_name, s_store_name, sum(netpaid) paid
    32   from ssales
    33   where i_color = 'chiffon'
    34   group by c_last_name, c_first_name, s_store_name
    35   having sum(netpaid) > (select 0.05*avg(netpaid) from ssales)