github.com/apache/beam/sdks/v2@v2.48.2/java/testing/tpcds/src/main/resources/queries/query21.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   from(select w_warehouse_name
    19              ,i_item_id
    20              ,sum(case when (cast(d_date as date) < cast ('1998-04-08' as date))
    21  	                then inv_quantity_on_hand
    22                        else 0 end) as inv_before
    23              ,sum(case when (cast(d_date as date) >= cast ('1998-04-08' as date))
    24                        then inv_quantity_on_hand
    25                        else 0 end) as inv_after
    26     from inventory
    27         ,warehouse
    28         ,item
    29         ,date_dim
    30     where i_current_price between 0.99 and 1.49
    31       and i_item_sk          = inv_item_sk
    32       and inv_warehouse_sk   = w_warehouse_sk
    33       and inv_date_sk    = d_date_sk
    34       and d_date between (cast ('1998-04-08' as date) - interval '30' day)
    35                      and (cast ('1998-04-08' as date) + interval '30' day)
    36     group by w_warehouse_name, i_item_id) x
    37   where (case when inv_before > 0
    38               then inv_after / inv_before
    39               else null
    40               end) between 2.0/3.0 and 3.0/2.0
    41   order by w_warehouse_name
    42           ,i_item_id
    43   limit 100