Categories
Database Development

how to optimize big result to sum in MySQL 5.7

Now I have a user consume history record table, sometimes the data is very big(>1million) per day.Now I have to calculate the table to get report data,this is my sql: SELECT SUM(consume_num) AS consumeNum, SUM(transin_num) AS transinNum , CASE WHEN COUNT(DISTINCT transin_user_num) – 1 < 0 THEN 0 ELSE COUNT(DISTINCT transin_user_num) – 1 END AS […]