I'm looking to calculate the difference between two record sets in MySQL.
Say I have the following table:
colname type attrbutes
id uInt PK
date date PK
count uInt
With this data:
id date count
1 2000-1-1 15
1 2000-2-1 20
2 2000-1-1 20
2 2000-2-1 30
I'm trying to get the following result (if the user selects dates 2000-1-1
and 2000-2-1
):
id count
1 5
2 10
What is a good way to do this?
Best Answer
Using the same table structure and data
Here is that data loaded
Please note that I added id 3 to demonstrate negative differences
Here is my proposed query
Notice I used the following:
Here is the output
Give it a Try !!!