Getting pct from SUM data
I'm trying to get my sql working to get % from data from 2 sum'd columns IE : SELECT SUM(NumCalls) as SUM_NumCalls, SUM(NumCompleted) as SUM_NumCompleted , (SUM_NumCompleted * 100 / SUM_NumCalls ) as `% Completed` FROM my_schema.my_table GROUP BY Company ;
Error Code: 1054. Unknown column 'SUM_NumCompleted' in 'field list'
Answer Answered by Ian Gilfillan in this comment.
You cannot use the alias there, as it hasn't been evaluated yet. Something like:
SELECT SUM(NumCalls) as SUM_NumCalls, SUM(NumCompleted) as SUM_NumCompleted, (SUM(NumCompleted) * 100 / SUM(NumCalls)) as ...