github.com/apache/beam/sdks/v2@v2.48.2/java/testing/tpcds/src/main/resources/queries/query80.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 ssr as
    18   (select  s_store_id as store_id,
    19            sum(ss_ext_sales_price) as sales,
    20            sum(coalesce(sr_return_amt, 0)) as `returns`,
    21            sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit
    22    from store_sales left outer join store_returns on
    23           (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number),
    24       date_dim,
    25       store,
    26       item,
    27       promotion
    28   where ss_sold_date_sk = d_date_sk
    29         and d_date between cast('1998-08-04' as date)
    30                    and (cast('1998-08-04' as date) +  interval '30' day)
    31         and ss_store_sk = s_store_sk
    32         and ss_item_sk = i_item_sk
    33         and i_current_price > 50
    34         and ss_promo_sk = p_promo_sk
    35         and p_channel_tv = 'N'
    36   group by s_store_id)
    37   ,
    38   csr as
    39   (select  cp_catalog_page_id as catalog_page_id,
    40            sum(cs_ext_sales_price) as sales,
    41            sum(coalesce(cr_return_amount, 0)) as `returns`,
    42            sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit
    43    from catalog_sales left outer join catalog_returns on
    44           (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number),
    45       date_dim,
    46       catalog_page,
    47       item,
    48       promotion
    49   where cs_sold_date_sk = d_date_sk
    50         and d_date between cast('1998-08-04' as date)
    51                    and (cast('1998-08-04' as date) +  interval '30' day)
    52          and cs_catalog_page_sk = cp_catalog_page_sk
    53         and cs_item_sk = i_item_sk
    54         and i_current_price > 50
    55         and cs_promo_sk = p_promo_sk
    56         and p_channel_tv = 'N'
    57  group by cp_catalog_page_id)
    58   ,
    59   wsr as
    60   (select  web_site_id,
    61            sum(ws_ext_sales_price) as sales,
    62            sum(coalesce(wr_return_amt, 0)) as `returns`,
    63            sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit
    64    from web_sales left outer join web_returns on
    65           (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number),
    66       date_dim,
    67       web_site,
    68       item,
    69       promotion
    70   where ws_sold_date_sk = d_date_sk
    71         and d_date between cast('1998-08-04' as date)
    72                    and (cast('1998-08-04' as date) +  interval '30' day)
    73          and ws_web_site_sk = web_site_sk
    74         and ws_item_sk = i_item_sk
    75         and i_current_price > 50
    76         and ws_promo_sk = p_promo_sk
    77         and p_channel_tv = 'N'
    78  group by web_site_id)
    79    select  channel
    80          , id
    81          , sum(sales) as sales
    82          , sum(`returns`) as `returns`
    83          , sum(profit) as profit
    84   from
    85   (select 'store channel' as channel
    86          , 'store' || store_id as id
    87          , sales
    88          , `returns`
    89          , profit
    90   from   ssr
    91   union all
    92   select 'catalog channel' as channel
    93          , 'catalog_page' || catalog_page_id as id
    94          , sales
    95          , `returns`
    96          , profit
    97   from  csr
    98   union all
    99   select 'web channel' as channel
   100          , 'web_site' || web_site_id as id
   101          , sales
   102          , `returns`
   103          , profit
   104   from   wsr
   105   ) x
   106   group by rollup (channel, id)
   107   order by channel
   108           ,id
   109   limit 100