I'm using SQL Server and I have the following query. I need to add the Percentage column. I need to calculate the percentage of Passed
over Total
but I do not know how to get the values of that same select to enter in the calculation.
SELECT
Data,
SUM(CASE WHEN Status = 'OK' THEN 1 ELSE 0 END) as Passed,
SUM(CASE WHEN Status = 'NOK' THEN 1 ELSE 0 END) as Failed,
COUNT(*) AS Total
FROM VWDADOSFPY
GROUP BY Data
ORDER BY Data DESC;
The table should look like this:
Data Passed Failed Total Porcentagem
2018-03-15 470 5 475 98,94%
2018-03-14 485 17 502 96,61%
2018-03-13 1631 74 1705 95,65%
Can anyone help?