blob: 4d4592737b387d36a6be6130bf47f56093ceab06 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
USE tpcds;
SELECT
SUBSTR(w_warehouse_name,1,20)
,sm_type
,web_name
,SUM(CASE WHEN (ws_ship_date_sk - ws_sold_date_sk) <= 30 THEN 1 ELSE 0 END) AS c30_days
,SUM(CASE WHEN (ws_ship_date_sk - ws_sold_date_sk) > 30 AND
(ws_ship_date_sk - ws_sold_date_sk) <= 60 THEN 1 ELSE 0 END ) AS c31_60_days
,SUM(CASE WHEN (ws_ship_date_sk - ws_sold_date_sk) > 60 AND
(ws_ship_date_sk - ws_sold_date_sk) <= 90 THEN 1 ELSE 0 END) AS c61_90_days
,SUM(CASE WHEN (ws_ship_date_sk - ws_sold_date_sk) > 90 AND
(ws_ship_date_sk - ws_sold_date_sk) <= 120 THEN 1 ELSE 0 END) AS c91_120_days
,SUM(CASE WHEN (ws_ship_date_sk - ws_sold_date_sk) > 120 THEN 1 ELSE 0 END) AS gt120_days
FROM
web_sales
,warehouse
,ship_mode
,web_site
,date_dim
WHERE
d_month_seq >= 1212 AND d_month_seq <= 1212 + 11
AND ws_ship_date_sk = d_date_sk
AND ws_warehouse_sk = w_warehouse_sk
AND ws_ship_mode_sk = sm_ship_mode_sk
AND ws_web_site_sk = web_site_sk
GROUP BY
SUBSTR(w_warehouse_name,1,20)
,sm_type
,web_name
ORDER BY SUBSTR(w_warehouse_name,1,20)
,sm_type
,web_name
LIMIT 100;