
- 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
How to sum current month records in MySQL?
To sum current month records, use the SUM() and MONTH() function. Let us first create a table −
mysql> create table DemoTable1889 ( DueDate date, Amount int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1889 values('2019-12-11',500); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1889 values('2019-11-11',1000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1889 values('2018-12-04',700); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1889 values('2017-12-10',300); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1889;
This will produce the following output −
+------------+--------+ | DueDate | Amount | +------------+--------+ | 2019-12-11 | 500 | | 2019-11-11 | 1000 | | 2018-12-04 | 700 | | 2017-12-10 | 300 | +------------+--------+ 4 rows in set (0.00 sec)
The current date is as follows −
mysql> select curdate(); +------------+ | curdate() | +------------+ | 2019-12-10 | +------------+ 1 row in set (0.00 sec)
Here is the query to sum current month records in MySQL −
mysql> select sum(Amount) from DemoTable1889 where MONTH(DueDate)=MONTH(curdate());
This will produce the following output −
+-------------+ | sum(Amount) | +-------------+ | 1500 | +-------------+ 1 row in set (0.00 sec)
- Related Articles
- How to sum selected column values based on specific month records in MySQL?
- Filter the records of current day, month and year in MySQL?
- Fetch date records comparing with the current date’s day and month in MySQL
- Display records from the current date till rest of the same month in MySQL?
- How to get last day of the current month in MySQL?
- How to get the first day of the current month in MySQL?
- SUM corresponding duplicate records in MySQL
- MySQL query to order by current day and month?
- Calling NOW() function to fetch current date records in MySQL?
- How to compare Year, Month and Day in a MySQL query and display matching records
- How to sum the values in the table by month with MySQL?
- How can fetch records from specific month and year in a MySQL table?
- MySQL SELECT query to return records with specific month and year
- MySQL to fetch records based on a specific month and year?
- How to select sum or 0 if no records exist in MySQL?

Advertisements