Skip to content

Tag: amazon-redshift

Multiple conditions in CASE WHEN statement

I’m working in SQL (Amazon Redshift) with Recruitment data where each applicant has multiple sources, which I’ve split into different columns called source_1, source_2, and source_3, along with a number_of_sources column to record how many sources that applicant has. We want each applicant to only…

Combining Data Across Multiple Data Fields

I am trying to create a common data field based on multiple columns below. When I try to use nvl i am getting blank values in the common field and its not getting picked up..The input and output tables are below: Input table model-manufacture model -CAM MODEL -schedule CX190 NM890 NM890 JK1231 LO121 LO121 VB1…

partition by customer for distinct items

select customer_id, row_number()over(partition by customer id order by date) as rn from table How to get same rn when Item Id is the same? Below did not work: #1 select customer_id, row_number()over(partition by customer id, Item Id order by date) as rn from table Answer We can try to use DENSE_RANK instead o…

DATEPART and DATEFIRST alternative for redshift

I’m trying to run in Redshift with the start day being Saturday. I tried using different syntax for SET DATEFIRST but it seems like it’s not supported (or I just can’t find the correct syntax for redshift). Are there any alternatives available? The documentation page only shows information f…