input_table
username input
A A10
B A9
C A8
D A7
E A0
F A4
like so on
How i can find sum of input by removing 'A' char from 'input' field
Try the below code
select SUM(SUBSTRING(input, 2)) from input_table
Try this, may work;)
MySQL 5.6 Schema:
CREATE TABLE input_table
(`username` varchar(1), `input` varchar(3))
;
INSERT INTO input_table
(`username`, `input`)
VALUES
('A', 'A10'),
('B', 'A9'),
('C', 'A8'),
('D', 'A7'),
('E', 'A0'),
('F', 'A4')
;
Query 1:
select sum(replace(input, 'A', '')) from input_table
| sum(replace(input, 'A', '')) |
|------------------------------|
| 38 |
Use RIGHT
function to get the number in the right side and CAST
it and then find the SUM
.
Query
SELECT SUM(CAST(RIGHT(input, LENGTH(input) - 1) AS UNSIGNED)) AS `SUM`
FROM input_table;
Try this also:
SELECT SUM(CAST(TRIM(LEADING 'A' FROM input)) AS UNSIGNED) AS total FROM table;