I currently have:
SELECT Name, COUNT(*) as Total
FROM DataTable
WHERE Name IN ('A', 'B', 'C')
GROUP BY Name
Resulting output:
Name Total
--------------
A 2
B 5
C 3
Instead I want this:
Name Total
--------------
A 10
B 10
C 10
Here 10 is a total of 2 + 5 + 3 (total number of records with name = A/B/C)
How do I do this?
To get your desired result you can use SUM() OVER () on the grouped COUNT(*). Demo
SELECT Name,
SUM(COUNT(*)) OVER () as Total
FROM DataTable
WHERE Name IN ('A', 'B', 'C')
GROUP BY Name
Get rid of the group by and use distinct:
select distinct Name, count(*) over() as Total
from t
where name in ('A', 'B', 'C')
rextester demo: http://rextester.com/WDMT68119
returns:
+------+-------+
| name | Total |
+------+-------+
| A | 10 |
| B | 10 |
| C | 10 |
+------+-------+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With