Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find sum by removing first character from string in mysql

Tags:

sql

php

mysql

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

like image 393
Anand Parmar Avatar asked Dec 13 '25 08:12

Anand Parmar


2 Answers

Try the below code

select SUM(SUBSTRING(input, 2)) from input_table
like image 98
Arun Avatar answered Dec 14 '25 21:12

Arun


Try this, may work;)

SQL Fiddle

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

Results:

| sum(replace(input, 'A', '')) |
|------------------------------|
|                           38 |
like image 25
Mippy Avatar answered Dec 14 '25 21:12

Mippy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!