0

I don't know how to add all count(*) results. I mean, if i have red publisher, who has got 2 books, and blue publisher with 6 books. I have to get how many books have each one and how many books are in total. The first part I've done. How to do the second one? My code:

 SELECT Publisher, count(*) AS ct 
 FROM  Stud.Book 
 Group by Publisher;
Toto
  • 89,455
  • 62
  • 89
  • 125
  • 2
    Possible duplicate of [How to use count and group by at the same select statement](https://stackoverflow.com/questions/2722408/how-to-use-count-and-group-by-at-the-same-select-statement) – Marcin Orlowski Sep 24 '18 at 10:13

2 Answers2

2

That's what rollup is for:

SELECT Publisher, count(*) AS ct 
FROM  Stud.Book 
Group by rollup(Publisher);
1

You should use grouping sets for that:

SELECT publisher, count(*) AS ct 
FROM  stud.book 
GROUP BY GROUPING SETS ((publisher), ());
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263