
- 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
Combine SUM and FORMAT in MySQL to format the result
Let us create a table −
mysql> create table DemoTable1950 ( Amount float ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1950 values(45.60); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1950 values(101.78); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1950 values(75.90); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1950 values(89.45); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1950;
This will produce the following output −
+--------+ | Amount | +--------+ | 45.6 | | 101.78 | | 75.9 | | 89.45 | +--------+ 4 rows in set (0.00 sec)
Following is the query to combine SUM and FORMAT in MySQL:
mysql> select format(sum(Amount),2) as TotalSum from DemoTable1950;
This will produce the following output −
+----------+ | TotalSum | +----------+ | 312.73 | +----------+ 1 row in set (0.00 sec)
- Related Articles
- Convert MySQL Unix-Timestamp format to date format?
- Find values with OR operator in MongoDB and format the result.?
- How to convert US date format to MySQL format in INSERT query?
- How to update the date format in MySQL?
- Format date in MySQL to return MonthName and Year?
- Select date from MySQL and format to text?
- How to convert Python date format to 10-digit date format for mysql?
- Format MySQL CURRENT_TIMESTAMP to AM & PM?
- How can MySQL produce the output in a vertical format rather than tabular format?
- Format date with DATE_FORMAT() and STR_TO_DATE() in MySQL
- Format MySQL date and convert to year-month-day
- Java Program to format Month in MMMM format
- How to convert a date format in MySQL?
- Convert string (varchar) to timestamp format in MySQL?
- MySQL select to convert numbers to millions and billions format?

Advertisements