select abs(-2.3)
Output of above code is 2.3
select abs(+4.567)
Output is 4.567
select abs(0.23)
It is 0.23
SELECT product, buy_price, sell_price, sell_price - buy_price AS difference FROM `plus2_price
Output is here
| product | buy_price | sell_price | difference | |
|---|---|---|---|---|
| Product1 | 10 | 15 | 5 | |
| Product1 | 20 | 15 | -5 | |
| Product1 | 10 | 10 | 0 | |
| Product1 | 20 | 25 | 5 |
SELECT product, buy_price, sell_price, sell_price - buy_price AS difference,
ABS( sell_price - buy_price ) AS ABS_difference FROM plus2_price
| product | buy_price | sell_price | difference | ABS_ difference |
|---|---|---|---|---|
| Product1 | 10 | 15 | 5 | 5 |
| Product1 | 20 | 15 | -5 | 5 |
| Product1 | 10 | 10 | 0 | 0 |
| Product1 | 20 | 25 | 5 | 5 |
SELECT product, buy_price, sell_price, sell_price - buy_price AS difference, ABS( sell_price - buy_price ) AS ABS_difference FROM plus2_price
WHERE ABS( sell_price - buy_price ) >0
More about SQL Where condition Query
The SQL Dump of this table is hereCREATE TABLE IF NOT EXISTS `plus2_price` (
`product` varchar(10) NOT NULL,
`buy_price` int(3) NOT NULL,
`sell_price` int(3) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `plus2_price`
--
INSERT INTO `plus2_price` (`product`, `buy_price`, `sell_price`) VALUES
('Product1', 10, 15),
('Product1', 20, 15),
('Product1', 10, 10),
('Product1', 20, 25);
SQL Math References
SIGN function : Sign of the argument
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.