Top "Group-by" questions

GROUP BY is a command in the SQL relational database standard for collapsing a group of rows that share common field value(s) into a single row.

Pandas sort by group aggregate and column

Given the following dataframe In [31]: rand = np.random.RandomState(1) df = pd.DataFrame({'A': ['foo', 'bar', 'baz'] * 2, 'B': rand.randn(6), 'C': …

python sorting group-by dataframe pandas
What does SQL clause "GROUP BY 1" mean?

Someone sent me a SQL query where the GROUP BY clause consisted of the statement: GROUP BY 1. This must be …

mysql sql group-by
Distinct pair of values SQL

Consider create table pairs ( number a, number b ) Where the data is 1,1 1,1 1,1 2,4 2,4 3,2 3,2 5,1 Etc. What query gives me the distinct values …

sql group-by distinct
How do I create a new column from the output of pandas groupby().sum()?

Trying to create a new column from the groupby calculation. In the code below, I get the correct calculated values …

python pandas group-by pandas-groupby
How do I use Group By based on a Case statement in Oracle?

I have an SQL-query where I use Oracle CASE to compare if a date column is less than or greater …

sql oracle group-by case
Ms Access Query: Concatenating Rows through a query

Suppose I have table in Ms Access with following information: ColumnA ColumnB 1 abc 1 pqr 1 xyz 2 efg 2 hij 3 asd My question …

sql ms-access group-by concatenation
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 …

python pandas dataframe group-by pandas-groupby
How to group data.table by multiple columns?

I'm using the data.table package to speed up some summary statistic collection on a data set. I'm curious if …

r group-by data.table
Python: get a frequency count based on two columns (variables) in pandas dataframe some row appers

Hello I have the following dataframe. Group Size Short Small Short Small Moderate Medium Moderate Small Tall Large I want …

python pandas group-by dataframe
MySQL: How do I join same table multiple times?

I have two tables ticket and attr. Table ticket has ticked_id field and several other fields. Table attr has 3 …

mysql sql group-by left-join