K
K
Konstantin KOltin2022-03-09 10:20:08
MySQL
Konstantin KOltin, 2022-03-09 10:20:08

SUM of a column of numbers with a comma?

As a result, only integers are calculated, tens and hundreds are not taken into account.
48.22
48.18
65 30.16 50
35.17 28.41 150 27.04 141 33.56 30.20 30.12 45.21 90 100 115 180 10.04 15.05 4.02

CREATE TABLE excel (
    Start varchar(255),
    Duration varchar(255),
    Position varchar(255),
    Volume varchar(255),
    Sensor_name varchar(255),
Geofences_Objects varchar(255),
    Fueled varchar(255),
    Deviation varchar(255)
);

62285879d28a9319204677.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2022-03-09
@KOltin

If the data is to be summarized, then there should not be any comma in them. The decimal separator for data in mysql is DOT.
And numeric data must be stored in the types of fields intended for this.
The list can be found in the documentation: https://dev.mysql.com/doc/refman/8.0/en/numeric-ty... and choose the most suitable one. It can be either a fixed point type (DECIMAL) or a floating point type (FLOAT).

V
Vladimir Korotenko, 2022-03-09
@firedragon

Somewhere like this, but it's better to change the types in the database

SELECT SUM(duration) as dumb,
SUM(CAST(REPLACE(duration,',','.') AS DECIMAL(30,2))) as casted 
FROM test.testtable;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question