Home > database >  SQL group by within a group
SQL group by within a group

Time:12-11

How can we use group by within separate categories? That is treat each category as it's own group and then group by something else within the category.

For instance in this Image, I would like to group by quarter only within a particular ISSN.

sample data

Expected result would be

expected result

CodePudding user response:

It is possible to group by more than one column:

select issn, quarter, count(*)
from t
group by issn, quarter

CodePudding user response:

Simply add columns -as prioritized- to group by, example:

SELECT * FROM MyTable GROUP BY ISSN, Quarter
  • Related