github.com/apache/beam/sdks/v2@v2.48.2/java/testing/tpcds/src/main/resources/queries/query59.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 wss as 18 (select d_week_seq, 19 ss_store_sk, 20 sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, 21 sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, 22 sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, 23 sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, 24 sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, 25 sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, 26 sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales 27 from store_sales,date_dim 28 where d_date_sk = ss_sold_date_sk 29 group by d_week_seq,ss_store_sk 30 ) 31 select s_store_name1,s_store_id1,d_week_seq1 32 ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 33 ,tue_sales1/tue_sales1,wed_sales1/wed_sales2,thu_sales1/thu_sales2 34 ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 35 from 36 (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 37 ,s_store_id s_store_id1,sun_sales sun_sales1 38 ,mon_sales mon_sales1,tue_sales tue_sales1 39 ,wed_sales wed_sales1,thu_sales thu_sales1 40 ,fri_sales fri_sales1,sat_sales sat_sales1 41 from wss,store,date_dim d 42 where d.d_week_seq = wss.d_week_seq and 43 ss_store_sk = s_store_sk and 44 d_month_seq between 1185 and 1185 + 11) y, 45 (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 46 ,s_store_id s_store_id2,sun_sales sun_sales2 47 ,mon_sales mon_sales2,tue_sales tue_sales2 48 ,wed_sales wed_sales2,thu_sales thu_sales2 49 ,fri_sales fri_sales2,sat_sales sat_sales2 50 from wss,store,date_dim d 51 where d.d_week_seq = wss.d_week_seq and 52 ss_store_sk = s_store_sk and 53 d_month_seq between 1185+ 12 and 1185 + 23) x 54 where s_store_id1=s_store_id2 55 and d_week_seq1=d_week_seq2-52 56 order by s_store_name1,s_store_id1,d_week_seq1 57 limit 100