github.com/apache/beam/sdks/v2@v2.48.2/java/testing/tpcds/src/main/resources/queries/query70.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 sum(ss_net_profit) as total_sum 19 ,s_state 20 ,s_county 21 ,grouping(s_state)+grouping(s_county) as lochierarchy 22 ,rank() over ( 23 partition by grouping(s_state)+grouping(s_county), 24 case when grouping(s_county) = 0 then s_state end 25 order by sum(ss_net_profit) desc) as rank_within_parent 26 from 27 store_sales 28 ,date_dim d1 29 ,store 30 where 31 d1.d_month_seq between 1212 and 1212+11 32 and d1.d_date_sk = ss_sold_date_sk 33 and s_store_sk = ss_store_sk 34 and s_state in 35 ( select s_state 36 from (select s_state as s_state, 37 rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking 38 from store_sales, store, date_dim 39 where d_month_seq between 1212 and 1212+11 40 and d_date_sk = ss_sold_date_sk 41 and s_store_sk = ss_store_sk 42 group by s_state 43 ) tmp1 44 where ranking <= 5 45 ) 46 group by rollup(s_state,s_county) 47 order by 48 lochierarchy desc 49 ,case when lochierarchy = 0 then s_state end 50 ,rank_within_parent 51 limit 100