生产上做报表遇到的sql问题

Posted by Clear Blog on August 29, 2017

做报表的需求,需要统计线上某时间数据,时间一般用时间戳即毫秒值来做记录,但是跑数据的时候提示 BIGINT UNSIGNED value is out of range

As of MySQL 5.5.5, overflow during numeric expression evaluation results in an error. For example, the largest signed BIGINT value is 9223372036854775807, so the following expression produces an error.

A change to part of your query, as following, would solve the issue.

( CAST( quantity AS SIGNED ) - COUNT( game_moblist.spawn_id ) ) AS quantity_to_spawn Otherwise you may require to change the sql_mode on unsigned operations.

mysql> SET sql_mode = ‘NO_UNSIGNED_SUBTRACTION’; and then run your query to get desired output.

select floor(floor(sum(cast(finish_time as signed) - cast(start_time as signed))/1000)/count(session_id)) master_video_time from video_session where start_time >= #{startTime} and start_time <= #{endTime}