Last active
December 6, 2020 19:22
-
-
Save prateeka/ff59add24bd6810ec4c6a0bc52aeb8c1 to your computer and use it in GitHub Desktop.
'All' level selecting 'min' member instead of 'firstChild' member
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
MIN(t_129.c0) AS c0, | |
MIN(t_129.c_39) AS c1, | |
t_129.c2 AS c2, | |
t_129.c3s0 AS c3s0 | |
FROM | |
( | |
SELECT | |
MIN(t_128.c0) AS c0, | |
MIN(t_128.c_39) AS c_39, | |
t_128.c2 AS c2, | |
t_128.c3s0 AS c3s0 | |
FROM | |
( | |
SELECT | |
CAST(SUM(factinternetsales_t73.orderquantity) AS BIGINT) AS c0, | |
CAST(NULL AS BIGINT) AS c_39, | |
dim_geo_country_t80.country AS c2, | |
dim_geo_country_t80.country AS c3s0 | |
FROM | |
as_adventure.factinternetsales AS factinternetsales_t73 | |
JOIN | |
( | |
SELECT | |
dimcustomer_t74.customerkey AS customerkey_c75, | |
dimcustomer_t74.gender AS gender_c76, | |
dimcustomer_t74.geographykey AS geographykey_c77 | |
FROM | |
as_adventure.dimcustomer AS dimcustomer_t74 | |
WHERE | |
dimcustomer_t74.gender = 'F' | |
GROUP BY | |
1, | |
2, | |
3 | |
) AS t_78 | |
ON | |
factinternetsales_t73.customerkey = t_78.customerkey_c75 | |
JOIN | |
as_adventure.dim_geo_postalcode AS dim_geo_postalcode_t79 | |
ON | |
t_78.geographykey_c77 = dim_geo_postalcode_t79.geographykey | |
JOIN | |
as_adventure.dim_geo_country AS dim_geo_country_t80 | |
ON | |
dim_geo_postalcode_t79.country = dim_geo_country_t80.country | |
WHERE | |
true | |
GROUP BY | |
3, | |
4 | |
UNION ALL | |
SELECT | |
CAST(NULL AS BIGINT) AS c0, | |
MIN(t_126.c_39) AS c_39, | |
t_121.c2 AS c2, | |
t_121.c3s0 AS c3s0 | |
FROM | |
( | |
SELECT | |
CAST(NULL AS BIGINT) AS c0, | |
MIN(t_111.c_39) AS c_39, | |
t_111.c2 AS c2, | |
COALESCE(t_125.c_52, t_111.c3s0) AS c3s0 | |
FROM | |
( | |
SELECT | |
t_124.c_63 AS c_63,--cy | |
t_124.c_52 AS c_52,--u-cy | |
t_124.c_62 AS c_62,--m-st-albm | |
t_124.c_67 AS c_67,--st-all | |
t_100.c_67 AS c_68--st-all | |
FROM | |
( | |
SELECT | |
t_123.c_63 AS c_63,--cy | |
t_123.c_52 AS c_52,--u-cy | |
t_123.c_62 AS c_62,--m-st-alb | |
t_97.c_67 AS c_67--st-all | |
FROM | |
( | |
SELECT | |
t_85.c_63 AS c_63,--cy | |
t_122.c_52 AS c_52,--u-cy | |
t_122.c_62 AS c_62--m-st | |
FROM | |
( | |
SELECT | |
t_84.country_c83 AS c_63--ctry | |
FROM | |
( | |
SELECT | |
dim_geo_country_t82.country AS country_c83 | |
FROM | |
as_adventure.dim_geo_country AS dim_geo_country_t82 | |
WHERE | |
dim_geo_country_t82.country = 'United States' | |
GROUP BY | |
1 | |
) AS t_84 | |
WHERE | |
true | |
GROUP BY | |
1 | |
) AS t_85 | |
JOIN | |
( | |
SELECT | |
t_89.c_52 AS c_52,--u-cy | |
t_94.c_58 AS c_62--m-st | |
FROM | |
( | |
SELECT | |
dim_geo_country_t87.country AS c_52, | |
dim_geo_state_t86.statekey AS c_53, | |
RANK() OVER (ORDER BY dim_geo_country_t87.country ASC NULLS FIRST ) AS rk_c51, | |
dim_geo_country_t87.country AS c_54 | |
FROM | |
as_adventure.dim_geo_state AS dim_geo_state_t86 | |
JOIN | |
as_adventure.dim_geo_country AS dim_geo_country_t87 | |
ON | |
dim_geo_state_t86.country = dim_geo_country_t87.country | |
WHERE | |
true | |
GROUP BY | |
1, | |
2, | |
4 | |
) AS t_89 | |
JOIN | |
( | |
SELECT | |
dim_geo_state_t90.statekey AS c_58, | |
ROW_NUMBER() OVER (ORDER BY dim_geo_country_t91.country ASC NULLS FIRST, dim_geo_state_t90."state" ASC NULLS FIRST ) AS rn_c57, | |
dim_geo_country_t91.country AS c_60, | |
dim_geo_state_t90."state" AS c_61 | |
FROM | |
as_adventure.dim_geo_state AS dim_geo_state_t90 | |
JOIN | |
as_adventure.dim_geo_country AS dim_geo_country_t91 | |
ON | |
dim_geo_state_t90.country = dim_geo_country_t91.country | |
WHERE | |
true | |
GROUP BY | |
1, | |
3, | |
4 | |
) AS t_94 | |
ON | |
t_89.rk_c51 = t_94.rn_c57 | |
GROUP BY | |
1, | |
2 | |
) AS t_122 | |
ON | |
t_85.c_63 = t_122.c_52 | |
GROUP BY | |
1, | |
2, | |
3 | |
) AS t_123 | |
JOIN | |
( | |
SELECT | |
dim_geo_country_t96.country AS c_52, | |
dim_geo_state_t95.statekey AS c_67 | |
FROM | |
as_adventure.dim_geo_state AS dim_geo_state_t95 | |
JOIN | |
as_adventure.dim_geo_country AS dim_geo_country_t96 | |
ON | |
dim_geo_state_t95.country = dim_geo_country_t96.country | |
WHERE | |
true | |
GROUP BY | |
1, | |
2 | |
) AS t_97 | |
ON | |
t_123.c_52 = t_97.c_52 | |
GROUP BY | |
1, | |
2, | |
3, | |
4 | |
) AS t_124 | |
JOIN | |
( | |
SELECT | |
dim_geo_country_t99.country AS c_52, | |
dim_geo_state_t98.statekey AS c_67 | |
FROM | |
as_adventure.dim_geo_state AS dim_geo_state_t98 | |
JOIN | |
as_adventure.dim_geo_country AS dim_geo_country_t99 | |
ON | |
dim_geo_state_t98.country = dim_geo_country_t99.country | |
WHERE | |
true | |
GROUP BY | |
1, | |
2 | |
) AS t_100 | |
ON | |
t_124.c_63 = t_100.c_52 | |
GROUP BY | |
1, | |
2, | |
3, | |
4, | |
5 | |
) AS t_125 | |
JOIN | |
( | |
SELECT | |
CAST(SUM(factinternetsales_t101.orderquantity) AS BIGINT) AS c_39, | |
dim_geo_country_t109.country AS c2, | |
dim_geo_country_t109.country AS c3s0, | |
dim_geo_city_t107.statekey AS c_49 | |
FROM | |
as_adventure.factinternetsales AS factinternetsales_t101 | |
JOIN | |
( | |
SELECT | |
dimcustomer_t102.customerkey AS customerkey_c103, | |
dimcustomer_t102.gender AS gender_c104, | |
dimcustomer_t102.geographykey AS geographykey_c105 | |
FROM | |
as_adventure.dimcustomer AS dimcustomer_t102 | |
WHERE | |
dimcustomer_t102.gender = 'F' | |
GROUP BY | |
1, | |
2, | |
3 | |
) AS t_106 | |
ON | |
factinternetsales_t101.customerkey = t_106.customerkey_c103 | |
JOIN | |
as_adventure.dim_geo_city AS dim_geo_city_t107 | |
ON | |
t_106.geographykey_c105 = dim_geo_city_t107.geographykey | |
JOIN | |
as_adventure.dim_geo_postalcode AS dim_geo_postalcode_t108 | |
ON | |
t_106.geographykey_c105 = dim_geo_postalcode_t108.geographykey | |
JOIN | |
as_adventure.dim_geo_country AS dim_geo_country_t109 | |
ON | |
dim_geo_postalcode_t108.country = dim_geo_country_t109.country | |
WHERE | |
true | |
GROUP BY | |
2, | |
3, | |
4 | |
) AS t_111 | |
ON | |
t_125.c_68 = t_111.c_49 | |
GROUP BY | |
3, | |
4 | |
) AS t_126 | |
CROSS JOIN | |
( | |
SELECT | |
CAST(SUM(factinternetsales_t112.orderquantity) AS BIGINT) AS c_39, | |
dim_geo_country_t119.country AS c2, | |
dim_geo_country_t119.country AS c3s0 | |
FROM | |
as_adventure.factinternetsales AS factinternetsales_t112 | |
JOIN | |
( | |
SELECT | |
dimcustomer_t113.customerkey AS customerkey_c114, | |
dimcustomer_t113.gender AS gender_c115, | |
dimcustomer_t113.geographykey AS geographykey_c116 | |
FROM | |
as_adventure.dimcustomer AS dimcustomer_t113 | |
WHERE | |
dimcustomer_t113.gender = 'F' | |
GROUP BY | |
1, | |
2, | |
3 | |
) AS t_117 | |
ON | |
factinternetsales_t112.customerkey = t_117.customerkey_c114 | |
JOIN | |
as_adventure.dim_geo_postalcode AS dim_geo_postalcode_t118 | |
ON | |
t_117.geographykey_c116 = dim_geo_postalcode_t118.geographykey | |
JOIN | |
as_adventure.dim_geo_country AS dim_geo_country_t119 | |
ON | |
dim_geo_postalcode_t118.country = dim_geo_country_t119.country | |
WHERE | |
true | |
GROUP BY | |
2, | |
3 | |
) AS t_121 | |
GROUP BY | |
3, | |
4 | |
) AS t_128 | |
GROUP BY | |
3, | |
4 | |
) AS t_129 | |
GROUP BY | |
3, | |
4 | |
ORDER BY | |
3 ASC NULLS FIRST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment