github.com/apache/beam/sdks/v2@v2.48.2/java/testing/tpcds/src/main/resources/queries/query50.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
    18     s_store_name
    19    ,s_company_id
    20    ,s_street_number
    21    ,s_street_name
    22    ,s_street_type
    23    ,s_suite_number
    24    ,s_city
    25    ,s_county
    26    ,s_state
    27    ,s_zip
    28    ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end)  as `30 days`
    29    ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and
    30                   (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end )  as `31-60 days`
    31    ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and
    32                   (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end)  as `61-90 days`
    33    ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and
    34                   (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end)  as `91-120 days`
    35    ,sum(case when (sr_returned_date_sk - ss_sold_date_sk  > 120) then 1 else 0 end)  as `>120 days`
    36  from
    37     store_sales
    38    ,store_returns
    39    ,store
    40    ,date_dim d1
    41    ,date_dim d2
    42  where
    43      d2.d_year = 2000
    44  and d2.d_moy  = 9
    45  and ss_ticket_number = sr_ticket_number
    46  and ss_item_sk = sr_item_sk
    47  and ss_sold_date_sk   = d1.d_date_sk
    48  and sr_returned_date_sk   = d2.d_date_sk
    49  and ss_customer_sk = sr_customer_sk
    50  and ss_store_sk = s_store_sk
    51  group by
    52     s_store_name
    53    ,s_company_id
    54    ,s_street_number
    55    ,s_street_name
    56    ,s_street_type
    57    ,s_suite_number
    58    ,s_city
    59    ,s_county
    60    ,s_state
    61    ,s_zip
    62  order by s_store_name
    63          ,s_company_id
    64          ,s_street_number
    65          ,s_street_name
    66          ,s_street_type
    67          ,s_suite_number
    68          ,s_city
    69          ,s_county
    70          ,s_state
    71          ,s_zip
    72  limit 100