通过从mysql中的字符串中删除第一个字符来查找sum

时间:2016-05-11 11:19:49

标签: php mysql sql

input_table

username  input
A         A10
B         A9
C         A8
D         A7
E         A0
F         A4

就像这样

如何通过从'input'字段中删除'A'char来找到输入的总和

4 个答案:

答案 0 :(得分:8)

尝试以下代码

select SUM(SUBSTRING(input, 2)) from input_table

答案 1 :(得分:3)

试试这个,可能有用;)

SQL Fiddle

MySQL 5.6架构

SELECT DATE_SUB('2016-05-11', INTERVAL INTPART1.n ...

查询1

(select max(leads_update_on) from tlb_leads)

<强> Results

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')
;

答案 2 :(得分:0)

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;

答案 3 :(得分:0)

Try this also:

SELECT SUM(CAST(TRIM(LEADING 'A' FROM input)) AS UNSIGNED) AS total FROM table;