- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to ignore specific records and add remaining corresponding records (numbers) in MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> Name varchar(20), -> Amount int -> ); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John',200); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris',150); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Mike',500); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('John',350); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+-------+--------+ | Name | Amount | +-------+--------+ | John | 200 | | Chris | 150 | | Mike | 500 | | John | 350 | +-------+--------+ 4 rows in set (0.00 sec)
Here is the query to ignore specific records and add remaining records (numbers) −
mysql> select sum(Amount) from DemoTable -> where Name!='John';
This will produce the following output −
+-------------+ | sum(Amount) | +-------------+ | 650 | +-------------+ 1 row in set (0.00 sec)
Advertisements