Question: SELECT section _ name, MAX ( IF ( EXTRACT ( YEAR FROM trunc _ month ) = 2 0 2 4 AND EXTRACT ( MONTH

SELECT
section_name,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=1, total_distinct_users, NULL)) AS January_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=2, total_distinct_users, NULL)) AS February_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=3, total_distinct_users, NULL)) AS March_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=4, total_distinct_users, NULL)) AS April_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=5, total_distinct_users, NULL)) AS May_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=6, total_distinct_users, NULL)) AS June_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=7, total_distinct_users, NULL)) AS July_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=8, total_distinct_users, NULL)) AS August_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=9, total_distinct_users, NULL)) AS September_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=10, total_distinct_users, NULL)) AS October_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=11, total_distinct_users, NULL)) AS November_2024,
MAX(IF(EXTRACT(YEAR FROM trunc_month)=2024 AND EXTRACT(MONTH FROM trunc_month)=12, total_distinct_users, NULL)) AS December_2024,
FROM
production_data.feb_2024_overall_feature_usage
GROUP BY
section_name
order by section_name
----
In this code I am transposing month names from rows to columns, which is a pivot. Now, I want to change this to remove all column names which are months from the future. I am using bigquery.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!