I am trying to run the following query :
Select T, COUNT(T) as CountOf, (COUNT(T)*100)/(SUM(COUNT(T))) AS percen FROM
(
select prod as T, x,y,z from table1
UNION ALL select prod as T, x,y,z from table2
UNION ALL select prod as T, x,y,z from table3
)
AS m
GROUP BY T ORDER BY COUNT(T) DESC;
The above query gives the error. I am able to run the query successfully without the 3rd parameter i.e. (COUNT(T)*100)/(SUM(COUNT(T))) AS percent
(Calculates the percentage distribution of the 2nd parameter i.e. CountOf
)
But when i include the percentage parameter, it gives error. Any help on this would be appreciated.
I don't like using distinct but if you are using sql server you can try
CTE option