Replace NULL values per partition

I want to fill NULL values in device column for each session_id with an associated non-NULL value. How can I achieve that? Here is the sample data: +————+——-+———+ | session_id | step …

Using columns in window function that are not in Group By, I get : SQL compilation error: [COLUMN_A] is not a valid group by expression

I’ve seen a lot of questions about this error, the closest one (as it’s using window function) to my issue would be this one My issue is that I use columns in the windows function that are not …

How to select TOP records in Postgres. Not a similar question

I have a table with three columns (City, Orderid, Total_quantity) and more than 500 rows. I want to fetch the top 50 records according to total_quantity wise. I can do this with rank_number but the …

Wrong syntax for OVER and PARTITION in MySQL syntax

SELECT Id, Price, CustomerId, ROW_NUMBER() OVER (PARTITION BY CustomerId) FROM Orders; I get the error “Syntax error: Unexpected ‘(‘ (opening parenthesis) Does MySQL not support this? I’m pretty …

SQL: Expression Not in GROUP BY Key

I have a transaction table t1 in Hive that looks like this: store_id cust_id zip_code transaction_count spend 1000 100 123 3 50 2000 200 …

If ID has both values A and B it should return AB

INPUT: ID VALUES 1 A 1 B 2 A 3 B OUTPUT: ID VALUES 1 AB 1 AB 2 A 3 B If ID has both values A and B it should return AB.

Min and max value per group keeping order

I have a small problem in Redshift with with grouping; I have a table like following: INPUT VALUE CREATED UPDATED ———————————— 1 ‘2020-09-10’ ‘2020-09-11’ …

Assign new value to every unique number in SQL Server

I am new to SQL Server and trying to do some operations Sample data: Amount | BillID ——-+——- 500 | 10009 500 | 1492 350 | 15892 222 | 15596 899 | 20566 350 | 9566 How can …

window functions and grouping – how to propagate data from row 1 through row 3 in a partition?

I have this query below: select Contact.IndividualID, Contact.IndividualID as ContactId, Contact.CaseNumber as CaseID, [Case].ProgramCode as Benefit, Contact.Email as EmailAddress, …

Cumulative balance across two tables

I want to get data from 2 tables ordering them by date: to get the cumulative balance for the customer The 2 tables that I want to get data from are my tables: transfers & trans_payments transfers:…