tagged [group-by]

Is there any difference between GROUP BY and DISTINCT

Is there any difference between GROUP BY and DISTINCT I learned something simple about SQL the other day: Has the same result as: What I am curious of, is there anything different in the way an SQL en...

4 May at 22:19

mysql count group by having

mysql count group by having I have this table: A movie can have multiple genres, so an ID is not specific to a genre, it is a many to many relationship. I want a query to find the total number of movi...

Counting Using Group By Linq

Counting Using Group By Linq I have an object that looks like this: In a `List` I want to output All distinct Name and how many times the particular appears in the collection. For example: I want the ...

21 Oct at 11:38

Group by month and year in MySQL

Group by month and year in MySQL Given a table with a timestamp on each row, how would you format the query to fit into this specific json object format. I am trying to organize a json object into yea...

29 Jul at 21:0

Linq GroupBy with each null value as a group

Linq GroupBy with each null value as a group I have an object with a nullable int property "GroupId". With a List of this object, I would like to do a GroupBy on this "GroupId". But if I do it, all th...

27 Feb at 08:47

Entity Framework skip take by group by

Entity Framework skip take by group by I a currently "paging" through a table ("Table1") that has the following fields { Policy, Name, Amount, Date} and there can be mulitple records in "Table1" for a...

15 Mar at 17:58

Pandas 'count(distinct)' equivalent

Pandas 'count(distinct)' equivalent I am using Pandas as a database substitute as I have multiple databases ([Oracle](https://en.wikipedia.org/wiki/Oracle_Database), [SQL Server](https://en.wikipedia....

30 Aug at 08:1

Relative frequencies / proportions with dplyr

Relative frequencies / proportions with dplyr Suppose I want to calculate the proportion of different values within each group. For example, using the `mtcars` data, how do I calculate the frequency o...

3 May at 07:57

How to concatenate strings of a string field in a PostgreSQL 'group by' query?

How to concatenate strings of a string field in a PostgreSQL 'group by' query? I am looking for a way to concatenate the strings of a field within a group by query. So for example, I have a table: | I...

Linq Grouping - aggregate, outside of a group by

Linq Grouping - aggregate, outside of a group by I've got a SQL query, that works as follows: How can I write an identical Linq query? The issue is, that as soon as I apply my grouping, I cannot acces...

22 Apr at 13:58

Group by variable integer range using Linq

Group by variable integer range using Linq I'm trying to group a set of data based on the range of an integer, by the range does not increase at a fixed interval. e.g. I have Item ID Price 1      ...

28 Jan at 19:48

C# Linq Group By on multiple columns

C# Linq Group By on multiple columns ``` public class ConsolidatedChild { public string School { get; set; } public string Friend { get; set; } public string FavoriteColor { get; set; } public...

8 Mar at 11:30

sql group by versus distinct

sql group by versus distinct Why would someone use a group by versus distinct when there are no aggregations done in the query? Also, does someone know the group by versus distinct performance conside...

Group by range using linq

Group by range using linq how can we use groupped ranges for equal or greater than ? ``` var data = new[] { new { Id = 0, Price = 2 }, new { Id = 1, Price = 10 }, new { Id = 2, Price = 30 }, ...

12 Dec at 10:34

LINQ to SQL: GroupBy() and Max() to get the object with latest date

LINQ to SQL: GroupBy() and Max() to get the object with latest date Consider a SQL Server table that's used to store events for auditing. The need is to get only that for each CustID. We want to get t...

10 Nov at 00:9

group by week in pandas

group by week in pandas I'm having this data frame: I want to aggregate this by `Name` and `Date` to get sum of quantities Details: : Group, the result should be at the beginning of the week (or just ...

18 Dec at 23:28

pandas - find first occurrence

pandas - find first occurrence Suppose I have a structured dataframe as follows: The `A` column has previously been sorted. I wish to find the first row index of where `df[df.A!='a']`. The end goal is...

31 Jan at 08:51

How to select the first row for each group in MySQL?

How to select the first row for each group in MySQL? In C# it would be like this: Linq-To-Sql translates it to the following T-SQL code: ``` SELECT [t3].[AnotherColumn], [t3].[SomeColumn] FROM ( SEL...

29 Jan at 10:15

LINQ Group By and select collection

LINQ Group By and select collection I have this structure I want to generate a list of `CustomerItems` via LINQ given a subset of `OrderItems`: which is a grouping of all the items a Customer has orde...

17 May at 14:41

Get statistics for each group (such as count, mean, etc) using pandas GroupBy?

Get statistics for each group (such as count, mean, etc) using pandas GroupBy? I have a data frame `df` and I use several columns from it to `groupby`: In the above way I almost get the table (data fr...

Client side GroupBy is not supported

Client side GroupBy is not supported I have the following Entity Framework Core 3.0 query: I get the following error: To run the query on the client, or par

linq distinct or group by multiple properties

linq distinct or group by multiple properties How can I using c# and Linq to get a `result` from the next list: ``` var pr = new List() { new Product() {Title="Boots",Color="Red", Price=1}, ne...

14 Dec at 10:56

ORDER BY date and time BEFORE GROUP BY name in mysql

ORDER BY date and time BEFORE GROUP BY name in mysql i have a table like this: i want oldest name first: (->doesn't work!) now it should give me first mad(has earlier date) then tom

2 Feb at 13:49

Group dataframe and get sum AND count?

Group dataframe and get sum AND count? I have a dataframe that looks like this: ``` Company Name Organisation Name Amount 10118 Vifor Pharma UK Ltd Welsh Assoc for Gastro & Endo 2700.00 10119 Vi...

LINQ: combining join and group by

LINQ: combining join and group by I have a query that combines a join and a group, but I have a problem. The query is like: ``` var result = from p in Products join bp in BaseProducts on ...

30 Sep at 12:43