Postgresql – merge duplicate rows where one row is null
I am using AWS Redshift. I have a table that looks like this: Id key value1 value2 value3 1 xxx A NULL NULL 1 xxx NULL B NULL 2 uuu NULL NULL C If the id is repeating, the entire…
I am using AWS Redshift. I have a table that looks like this: Id key value1 value2 value3 1 xxx A NULL NULL 1 xxx NULL B NULL 2 uuu NULL NULL C If the id is repeating, the entire…
So I'm solving a question of a project, and I need to calculate the Compound Annual Growth Rate (CAGR), together with the total sales of the top 5 EV makers from fiscal year 2022 to 2024. I found out the…
I need to insert data into new table person_department using recursion. My tables for now: person id group_id 800 10 805 21 department id name group_id parent_id 1 ABC 10 5 2 TY 11 5 5 OOO null 9 6…
I want to loop through columns ['A', 'B', 'C'] and pass the column names to a select statement in SQL, such as SELECT * FROM table_name WHERE table_name.`A` IS NULL Thus each select statement would yield a result set based…
Here my customers table: id name 1 abc 2 bcd 3 cde 4 def and the shifts table: id id1 id2 1 1 2 2 1 3 1 3 my expected output is: name num abc 3 bcd 1 cde…
Example: Input Records Output Required: For each id, values of code1 and code2 for code3="in" should get copied to values of code1 and code2 where code3="out". I am doing: select distinct id from input_table where code3="in"; Applying join and taking…
I'm working on a project and I need to answer a question with the same context as the question title. To be honest, I'm not sure if I understand the question correctly, but here is my approach so far. Firstly,…
I am trying to check if there are matching emails in multiple tables, and if there are, then display the status of the emails per table. Here is the query I've been using to check 3 tables: SELECT rr.`email` ,…
I have a table people(gid int, name varchar) with data: gid name 1 Bill 2 Will 2 Musk 2 Jack 1 Martin 1 Jorge now I want to get a result set like below: gid representative(varchar) 1 Bill, Martin 2…
As part of a larger Postgres query, I generate all years between two given timestamps (timestamptz): select to_char(generate_series, 'YYYY') from generate_series( '2022-06-14 11:00:00.000+00'::timestamptz, '2023-06-14 11:00:00.000+00'::timestamptz, '1 year' ); Which returns: '2022' '2023' The issue is, if there is less than…