github.com/apache/beam/sdks/v2@v2.48.2/java/testing/tpcds/src/main/resources/queries/query46.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  select  c_last_name
    18         ,c_first_name
    19         ,ca_city
    20         ,bought_city
    21         ,ss_ticket_number
    22         ,amt,profit 
    23   from
    24     (select ss_ticket_number
    25            ,ss_customer_sk
    26            ,ca_city bought_city
    27            ,sum(ss_coupon_amt) amt
    28            ,sum(ss_net_profit) profit
    29      from store_sales,date_dim,store,household_demographics,customer_address 
    30      where store_sales.ss_sold_date_sk = date_dim.d_date_sk
    31      and store_sales.ss_store_sk = store.s_store_sk  
    32      and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk
    33      and store_sales.ss_addr_sk = customer_address.ca_address_sk
    34      and (household_demographics.hd_dep_count = 5 or
    35           household_demographics.hd_vehicle_count= 3)
    36      and date_dim.d_dow in (6,0)
    37      and date_dim.d_year in (1999,1999+1,1999+2) 
    38      and store.s_city in ('Midway','Fairview','Fairview','Midway','Fairview') 
    39      group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr
    40      where ss_customer_sk = c_customer_sk
    41        and customer.c_current_addr_sk = current_addr.ca_address_sk
    42        and current_addr.ca_city <> bought_city
    43    order by c_last_name
    44            ,c_first_name
    45            ,ca_city
    46            ,bought_city
    47            ,ss_ticket_number
    48    limit 100