nix, shell, perl, php, mysql and mac os x tips and tricks

Wednesday, September 23, 2015

MySQL query to compare two COUNT results to get a percentage

 keyed.keyed_codes AS "Entered Codes",
 totals.total_table AS "Total Codes",
 ROUND(((keyed.keyed_codes/totals.total_table)*100),2) AS "Percent Keyed"
(SELECT count(*) AS keyed_source FROM `table` WHERE code RLIKE "^[1-9]" AND timestamp BETWEEN '20150801000000' AND '20150831000000') AS keyed,
(SELECT count(*) AS total_table FROM `table` WHERE timestamp BETWEEN '20150801000000' AND '20150831000000') AS totals

No comments:

Post a Comment