Sample Header Ad - 728x90

Dynamic data used as column name in Amazon Redshift

0 votes
1 answer
2289 views
I am trying to use a year-month dynamic function to use it as a column name in Amazon Redshift. I don't want to write a hardcode for that. The database tool I'm using is DBeaver Ultimate and the code is the following:
create table test diststyle all 
as	(
		select 
				psid
				,count(case when year_month = convert(bigint, to_char(date_trunc('month', current_date) - interval '14 month', 'yyyymm')) then psid else null end) as to_char(date_trunc('month', current_date - interval '14 month'), 'yyyymm') **--column I want**
				,count(case when year_month = to_char(date_trunc('month', current_date) - interval '13 month', 'yyyymm') then psid else null end) as "202202" --hardcode
		from 	tb_app_opened_globoplay_redu
		group by psid
	);
Can you please help me with that?
Asked by vinifts (1 rep)
Mar 6, 2023, 01:38 PM
Last activity: Mar 16, 2023, 06:27 PM