Im trying to have a Total row at the end of query result im using MS-SQL 2012, need some help heres my query
SELECT
PropertyValue As Answer,Count(*) As rCount
FROM
QuestionerDetail AS Temp
where
QuestionId = 42 and FormId = 1
GROUP BY PropertyValue
Union All
SELECT 'Total',sum(rCount)
FROM
temp
Im doing something really wrong here.
The Result should be like
Answer rCount
-------------
One 10
Two 25
Total 35
Thanks.
You can't use the alias in another part of the union.
Try below instead:
SELECT
PropertyValue As Answer, Count(*) As rCount
FROM
QuestionerDetail AS Temp
where
QuestionId = 42 and FormId = 1
GROUP BY PropertyValue
Union All
SELECT 'Total', COUNT(*)
FROM
QuestionerDetail
where
QuestionId = 42 and FormId = 1
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