
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Find sum by removing first character from a string followed by numbers in MySQL?
The strings (column values) begun with a character and rest of the string has numbers. We want the sum of these numbers −
J230 A130s C13
For this, use SUBSTRING() function along with SUM().
Let us first create a table −
mysql> create table DemoTable761 (Price varchar(100)); Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable761 values('J230'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable761 values('A130'); Query OK, 1 row affected (0.70 sec) mysql> insert into DemoTable761 values('C13'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable761 values('D456'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable761 values('B6'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable761;
This will produce the following output -
+-------+ | Price | +-------+ | J230 | | A130 | | C13 | | D456 | | B6 | +-------+ 5 rows in set (0.00 sec)
Following is the query to find the sum by removing first character from a string followed by numbers in MySQL −
mysql> select sum(substring(Price,2)) from DemoTable761;
This will produce the following output -
+-------------------------+ | sum(substring(Price,2)) | +-------------------------+ | 835 | +-------------------------+ 1 row in set (0.00 sec)
- Related Articles
- Program to find maximum sum by removing K numbers from ends in python
- C++ Rearrange a string in sorted order followed by the integer sum
- Removing nth character from a string in Python program
- Filter column value by the first character in MySQL
- Python program for removing nth character from a string
- Find longest palindrome formed by removing or shuffling chars from string in Python
- Find longest palindrome formed by removing or shuffling chars from string in C++
- Removing first k characters from string in JavaScript
- Python program for removing n-th character from a string?
- Java program for removing n-th character from a string
- MySQL order by string with numbers?
- How to ORDER BY last 2 character string in MySQL?
- How to insert new string within a string subsequent to removing the characters from the original string by using MySQL function?
- MySQL query to sort by certain last string character?
- Select all except the first character in a string in MySQL?

Advertisements