I want to display the subtraction
of two values from two
different rows using a SQL
query.
This is the table structure:
------------------------------------
id | name | sub1 | sub2 | date
------------------------------------
1 | ABC | 50 | 75 | 2014-11-07
2 | PQR | 60 | 80 | 2014-11-08
I want to subtract date 2014-11-08 subject marks from date 2014-11-07.
Output should be like as
| sub1 | sub2 |
---------------
| 10 | 5 |
You can use a join to get the rows and then subtract the values:
SELECT(t2.sub1 - t1.sub1) AS sub1, (t2.sub2 - t1.sub2) AS sub2
FROM table t1 CROSS JOIN
table t2
WHERE t1.date = '2014-11-08' AND t2.id = '2014-11-07';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With