Skip to content
Advertisement

Tag: group-by

GROUP BY with Key:Value filters for each group

Given a table with following schema: RecordId ProcessId Data 80830F00-379C-11EA-96B7-372060281AFC 1 4.2 80830F00-379C-11EA-96B7-372060281AFC 2 445588662211448 80830F00-379C-11EA-96B7-372060281AFC 7 1 791F6D30-379C-11EA-96B7-372060281AFC 1 3.3 791F6D30-379C-11EA-96B7-372060281AFC 2 999999999999999 791F6D30-379C-11EA-96B7-372060281AFC 7 2 So the RecordId represents some grouping key and each ProcessId has its Data. Now I have a filter which looks like this: So the key is ProcessId and value is Data. Question How

How do I return a row with 0 if the group by has 0 records?

I have this alert_levels table: Then I have this alerts table The alert_level_id in the alerts table is a foreign key of id from the alert_levels table. What I want is to count the number of occurences of each alert_type grouped by the alert_level_id whithin a chosen time period. And if there is no occurency then it should show 0.

SQL Count Customers where Products are the same

I have a problem. I have a SQL-database named customers with the 3 columns Country, CustomerID and Product. With that database, I want to count all the customers which bought the products bike, flask and helmet but grouped by the country as you can see in the following picture. Is there a chance you can help me out with that?

Group by month and name SQL

I need some help with SQL. I have Table1 with columns Id, Date1 and Date2 Table2 with columns Table1Id and Table2Id Table3 with columns Id and Name Here is my try: I need to take Count(date2)/Count(date1) grouped by monthes and name. I have no idea how to do that, as there is no table with monthes. DB – Postgres sample

Query with group by with CustID and amounts daily and MTD

I have the following data: ID username Cost time 1 test1 1 2021-05-22 11:48:36.000 2 test2 2 2021-05-20 12:55:22.000 3 test3 5 2021-05-21 00:00:0-0.000 I would like to count the costs for the username with a daily figure and a month to date figure in once table I have got the following This will return the monthly figures and changing

Count from multiple columns and rows simultaneously in SQL

I have a table of matches which look like: I need to find the total matches played by every team and the output should be like this: I know about SUM() and GROUP BY clauses but not able to do it on multiple columns. Any help would be highly appreciated. Answer You can use union all to unpivot the data

Advertisement