Mysql varchar (38) Statistical problems

The

database has a doneNum field that represents the number of completions. It was originally designed as varchar (38) with this schedule in mind.

clipboard.png

doneNum sum(doneNum)

clipboard.png

I would like to ask you, is there any other solution?

Mar.25,2021

If the quantity of

is not large, change the field type of the database directly, and write a script to deal with the original content.

if the quantity is large, you can choose preprocessing. Under the condition that the demand must remain unchanged, the calculation can be processed regularly and the results can be stored temporarily.


first complete the urgent business requirements, and then re-create the field of int (38), because this is supposed to be an integer, and then fill in the numerical value, and there is no need to get a varchar, or you can directly add an index to varchar


in the project, there are two solutions:

  1. is still stored using varchar (38), and summarization is implemented in the program. PHP uses BCMath, to ensure that precision is not lost.
  2. is stored using decimal (20518), which makes it easy to reconcile the accounts, which can be reconciled through SQL without the need for a program to count.
Menu