Mysql Minus Operator

Mysql Minus Query return the calculated value from subtracting the maximum value and minimum value.

Mysql Minus Operator

     

Mysql Minus Query  return the calculated value from subtracting the maximum value and minimum value.

Query for creating table name Employee:

The Tutorial illustrate an example from 'Mysql Minus Query'. To understand and elaborate example we create a table 'employee' with required fieldnames and datatypes respectively.

 

 

 

mysql> CREATE TABLE Employee(
    ->              Empid int(10),
    ->              Empname varchar(60),
    ->              Salary int(90),
    ->              DOB date
    ->            );
Query OK, 0 rows affected (0.01 sec)

Query for  insertion of data in table:

The Query insert into is used to add the records and rows to the table 'Employee'.

mysql>     INSERT INTO Employee (Empid,Empname,Salary,DOB) VALUES
    ->     (01,'Habib',2014,20041202),
    ->     (02,'Karan',4021,20030411),
    ->     (03,'Samia', 22,20080223),
    ->     (04,'Hui Ling', 25,20081015),
    ->     (05,'Yumie', 29,19990126);
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

Query to view data inserted in table:

The Query select is used to return the records detail from table employee.

mysql> select * from employee;

Output:-

+-------+----------+--------+------------+
| Empid | Empname  | Salary | DOB        |
+-------+----------+--------+------------+
|     1 | Habib    |   2014 | 2004-12-02 |
|     2 | Karan    |   4021 | 2003-04-11 |
|     3 | Samia    |     22 | 2008-02-23 |
|     4 | Hui Ling |     25 | 2008-10-15 |
|     5 | Yumie    |     29 | 1999-01-26 |
+-------+----------+--------+------------+
5 rows in set (0.00 sec)

Query to use minus operator to the data of the table:

The Query Mysql minus query is used to find the difference between the maximum salary and minimum salary as deducated salary fieldname from table employee.

mysql> select max(salary)-min(salary)as DeductedSalary from employee;
+----------------+
| DeductedSalary |
+----------------+
|           3999 |
+----------------+
1 row in set (0.00 sec)

Advertisements

 

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

Mysql Minus Operator

Posted on: January 24, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Mysql Minus Operator  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
saranraj subramaniam
December 29, 2011
regarding minus query

wat's the another way of writing the query for the following query, select sid from sailor where sid in (select r.sid from reserv r, boats b where color like 'red' and b.bid = r.bid )minus select sid from sailor where sid in (select r.sid from reserv r, boats b where color like 'green' and b.bid = r.bid )

Ads

 

Ads