C# Linq Group By on multiple columns [duplicate]

var consolidatedChildren = from c in children group c by new { c.School, c.Friend, c.FavoriteColor, } into gcs select new ConsolidatedChild() { School = gcs.Key.School, Friend = gcs.Key.Friend, FavoriteColor = gcs.Key.FavoriteColor, Children = gcs.ToList(), }; var consolidatedChildren = children .GroupBy(c => new { c.School, c.Friend, c.FavoriteColor, }) .Select(gcs => new ConsolidatedChild() { School = gcs.Key.School, … Read more

must appear in the GROUP BY clause or be used in an aggregate function

[*] Yes, this is a common aggregation problem. Before SQL3 (1999), the selected fields must appear in the GROUP BY clause[*]. To workaround this issue, you must calculate the aggregate in a sub-query and then join it with itself to get the additional columns you’d need to show: SELECT m.cname, m.wmname, t.mx FROM ( SELECT … Read more

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

PostgreSQL 9.0 or later: Modern Postgres (since 2010) has the string_agg(expression, delimiter) function which will do exactly what the asker was looking for: SELECT company_id, string_agg(employee, ‘, ‘) FROM mytable GROUP BY company_id; Postgres 9 also added the ability to specify an ORDER BY clause in any aggregate expression; otherwise you have to order all … Read more

Using LIMIT within GROUP BY to get N results per group?

You could use GROUP_CONCAT aggregated function to get all years into a single column, grouped by id and ordered by rate: SELECT id, GROUP_CONCAT(year ORDER BY rate DESC) grouped_year FROM yourtable GROUP BY id Result: ———————————————————– | ID | GROUPED_YEAR | ———————————————————– | p01 | 2006,2003,2008,2001,2007,2009,2002,2004,2005,2000 | | p02 | 2001,2004,2002,2003,2000,2006,2007 | ———————————————————– And then … Read more

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

Quick Answer: The simplest way to get row counts per group is by calling .size(), which returns a Series: df.groupby([‘col1′,’col2’]).size() Usually you want this result as a DataFrame (instead of a Series) so you can do: df.groupby([‘col1’, ‘col2’]).size().reset_index(name=”counts”) If you want to find out how to calculate the row counts and other statistics for each … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)