How To Do Percent/Total in SQL?
MySQL: SELECT ROUND( 100.0 * ( SUM(IF(cust_id = 541, 1, 0)) / COUNT(order_id) ), 1) AS percent_total FROM orders; Edit I guess it helps if I would have noticed the postgres tag. I thought it was a MySQL question. PostgreSQL: SELECT ROUND( 100.0 * ( SUM(CASE WHEN cust_id = 541 THEN 1 ELSE 0 END)::numeric … Read more