Skip to content
Advertisement

Tag: group-by

SQL Server: Counts and Percentage by Group

I’ve tried the suggestions I’ve found on SO and cannot get the results I’m looking for which is this: I am able to get the first two columns with this code: — What I’ve tried: Trying to use a calcuation in a subquery to represent the total number of rows in the table is beyond me so far, so I

SQL GROUP BY with LEFT JOIN MS SQL Server

I have a calendar table (c) with a set of 3 month dates: I have a Stats table (s) with views of each product on the website. I need to count the views per product per month whether there are views or not. I have followed many SO answers (SQL – Group By with Left Join) and I cannot see

SQL SUM values by DISTINCT column after JOIN

I’ve been searching the forums for a solution for hours now but I couldn’t quite find the one that is fitting for my problem. I have two tables: members **************** id name city 1 John Boston 2 Maria Boston 3 Steve London 4 Oscar London 5 Ben Singapore donations ******************** member_id amount 1 100 1 150 2 300 3 50

How to select other rows in GROUP BY

Sorry for the bad title. I don’t know how to summarize it better. I have a table with unix timestamps and other values, like the following. time value 1620916380 110 1620916440 100 1620916500 120 1620916560 120 1620916660 90 The entries are always one minute apart. I want to group entries into 5-minute blocks with the value averaged. Currently I use

Complicated group by – windows

Can you please help with the following grouping: Name can have states that can be repeated several times and it is essential in output to have all the state changes over time and to have the starting date of the state Here is the input data: Desired output Answer Assuming you want to find the start date per consecutive sequence

Lead window function in mysql to find sales

Given this table. I would like to know for each day how many different customers made a sale on date t and and t+1. The result for date 2021-06-30 is 2 because customer 1 and 3 made a sale in t and t+1. Answer Use LEAD() window function for each distinct combination of date and customer to create a flag

Advertisement