github.com/apache/beam/sdks/v2@v2.48.2/java/testing/tpcds/src/main/resources/queries/query9.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 case when (select count(*)
    18                    from store_sales 
    19                    where ss_quantity between 1 and 20) > 25437
    20              then (select avg(ss_ext_discount_amt) 
    21                    from store_sales 
    22                    where ss_quantity between 1 and 20) 
    23              else (select avg(ss_net_profit)
    24                    from store_sales
    25                    where ss_quantity between 1 and 20) end bucket1 ,
    26         case when (select count(*)
    27                    from store_sales
    28                    where ss_quantity between 21 and 40) > 22746
    29              then (select avg(ss_ext_discount_amt)
    30                    from store_sales
    31                    where ss_quantity between 21 and 40) 
    32              else (select avg(ss_net_profit)
    33                    from store_sales
    34                    where ss_quantity between 21 and 40) end bucket2,
    35         case when (select count(*)
    36                    from store_sales
    37                    where ss_quantity between 41 and 60) > 9387
    38              then (select avg(ss_ext_discount_amt)
    39                    from store_sales
    40                    where ss_quantity between 41 and 60)
    41              else (select avg(ss_net_profit)
    42                    from store_sales
    43                    where ss_quantity between 41 and 60) end bucket3,
    44         case when (select count(*)
    45                    from store_sales
    46                    where ss_quantity between 61 and 80) > 10098
    47              then (select avg(ss_ext_discount_amt)
    48                    from store_sales
    49                    where ss_quantity between 61 and 80)
    50              else (select avg(ss_net_profit)
    51                    from store_sales
    52                    where ss_quantity between 61 and 80) end bucket4,
    53         case when (select count(*)
    54                    from store_sales
    55                    where ss_quantity between 81 and 100) > 18213
    56              then (select avg(ss_ext_discount_amt)
    57                    from store_sales
    58                    where ss_quantity between 81 and 100)
    59              else (select avg(ss_net_profit)
    60                    from store_sales
    61                    where ss_quantity between 81 and 100) end bucket5
    62  from reason
    63  where r_reason_sk = 1