12 March 2014

How to Subtract Two values in SQL query

Problem: How to subtract two values in a sql query to get the difference ? 

Solution: To subtract two values in sql, simply use  - (minus) between two values.

For Example:

SELECT sellprice - costprice AS profit FROM account


SELECT: is used in a statement which returns a result from one or more tables. It is known to be DML language (Data Manipulation Language)
AS : used to give a alias name to the column in result.

(If you found this article useful then share with your friends.)

No comments: