This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In our application, we needed a different type of Mathematical Calculations using any values, variables, parameters and columns.
The RDBMS Product like: SQL Server, PostgreSQL and MySQL supports basic addition, subtraction, multiplication and division.
Also, RDBMS Products have different types of aggregate functions for calculating the SUM and Average.
Various Mathematical operations are available in the Database System, so we don’t require any dependency of Application because we can also tune and authenticate Mathematical operation at the database level.
Below is some sample Mathematical Operations for MySQL.
This sample based on static values. You can use any variable, parameters and column to perform the same kind of Mathematical operation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
SELECT 8 + 8; -- Ans: 16 SELECT 1 + 2 + 3 + 8 + 88 + 458; -- Ans: 560 SELECT 2.5 + 4.5; -- Ans: 7.0 SELECT .456987 + .000887452; -- Ans: 0.457874452 SELECT 2.75 + -4.25; -- Ans: -1.50 SELECT 16 - 8; -- Ans: 8 SELECT 988 - 808; -- Ans: 180 SELECT 9.5 - 8.1; -- Ans: 1.4 SELECT 8.9 - 10.2; -- Ans: -1.3 SELECT 8 - 4 - 1; -- Ans: 3 SELECT .81 - .78; -- Ans: 0.03 SELECT 10 * 8; -- Ans: 80 SELECT 2 * -8; -- Ans: -16 SELECT 3 * 7 * 8; -- Ans: 168 SELECT 2.40 * 8; -- Ans: 19.20 SELECT .7 * .8; -- Ans: 0.56 SELECT 1/2; -- Ans: 0.5000 SELECT 1.0/2.0; -- Ans: 0.500000 SELECT 0/10; -- Ans: 0.0000 SELECT 100/14; -- Ans: 7.1429 SELECT -78.0/8.5; -- Ans: -9.17647 SELECT .8/.1; -- Ans: 8.00000 SELECT ((100 + 100) * .08); -- Ans: 16.00 SELECT (10 - 8)/20; -- Ans: 0.1000 SELECT (8.0 - 5.0)/3.0; -- Ans: 1.00000 SELECT ((50 + 50) - (20 + 20)); -- Ans: 60 |