SQL to get 3 adjacent actions without duplicate from the flags

I have a question that a little bit similar with question#66044663 but more complicated. Here’s my dummy data. I want to get 3 adjacent actions(no duplicate) from the flag by each user. Here’s the …

SQL – Count rows based on matching columns and value range

Please see below query using T-SQL with SSMS. There are three tables: B, G and L. B has a column Bname G has 2 columns Gname, Gross L has 2 columns Bname, Gname Gross column is an INT ranging …

Group and subquery issue

This is my sample data CREATE TABLE customer1 ( rating int(9), genre varchar(100), title varchar(100) ); INSERT INTO customer1 (rating, genre, title) VALUES (2, ‘A’, ‘abc’), (4, ‘A’, ‘…

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, …

How to multiply all values in one column to make one number?

In SQL Server, I am trying to multiply all values of a calculated column in a table in descending date order, to produce one number. This is so I can calculate a factor that can be applied to a …

convert access group by query to sql server query

I’m unable to convert MS Access query to SQL SERVER Query, with changing the group by columns because it will effect in the final result. The purpose of this query is to calculate the Creditor and …

SQL GROUP BY and kind of rereduce afterwards

I’m using PostgreSQL v.11. I have a table with 3 columns. My goal is to find redundancy inside data. First of all, I do a simple GROUP BY: SELECT client, block, “date” FROM lines GROUP BY …

SQL group and summing at new row

I have an issue where I am trying to create a new “row” (not part of the database) where it only gives me the SUM of the “count” column. I am wondering if that is possible? I tried …

SQL Server Sum specific transaction type amounts

I have a temp table (#general) that contains Account number, transaction type, Amount info as below AccountNumber Tran_Type Credit 96551AQ6 TSCNYAEUQF 0.0000000 96551AQ6 TSCNYAEUQF …

Compare two values in a row

select event_slots.id as event_slot_id, u.first_name, u.id AS user_id, sum(case when next_round = 1 then 1 else 0 end) AS yes, sum(case when next_round = 2 then 1 else 0 end) AS no from event_slots …