Skip to content
Advertisement

Tag: group-by

Group By Month between two dates

I have a table that lists all employees and their respective start and end dates I want to be able to count the number of active employees in each month. Is there a way to do this via a single query (eg groupBy) rather than generating multiple queries for each month? As an example, the table above should return: Dec

Grouping by multiple columns in a range in postgres

I have a couple tables (pega.race exists too we just don’t need any of the data for this) What I want is to get an average result for each combination (permutation?) of speed/strength/wind/lightning/water/fire in a range. So from 0-2.25, 2.25-4.5, 4.5-6.75, and 6.75-9. They have to be within 0-9. No values exist outside that. So I want an avg result

ORA-00937: not a single-group group function Workaround

This is my query which produces this error: ORA-00937: not a single-group group function Expected result for the last column – first order of every customer: I know that I have to use GROUP BY clause to handle this error, but it seems rather inappropriate to group by all the other columns.. I know that this is a limitation in

How to group data by past few weeks?

I have an original table like this, Can I group my data using GROUP BY in SQL to get the aggregate value by each week? My expected output will be like, Answer This is a way of doing it, probably not the best way however. Personally, I feel like this list is not something you’d want to do in SSMS.

SQL GROUP BY columns with inverted values

Suppose I’ve a table with like this: Where G1, G3 are VARCHAR and G2, G4 are INT If I do a simple GROUP BY on G1..G4 I get: I’m wondering if is possible to aggregate on inverted value G1,G2 <-> G3,G4. What I want to achieve is a result like this: What I tried is to get the inverted rows,

Advertisement