In my MySQL DB I have a table like this
| - value - | - date - |
|------------------------|
| 1 | 01.01.2016 |
| 2 | 02.01.2016 |
| 3 | 04.02.2016 |
| 5 | 01.01.2017 |
| 1 | 02.01.2017 |
| 5 | 04.02.2017 |
As result, I would like to have a value differences of rows with equal dates (regarding only the day and the month).
So basically I want this as result:
| - value - | - date - |
|------------------------|
| 1 - 4 | 01.01 |
| 2 - 1 | 02.01 |
| 3 - 5 | 04.02 |
How can I do it in SQL? I can use a nested SELECT to get data of one year like this:
SELECT col FROM (
SELECT value,date FROM Table
WHERE date BETWEEN '2016-01-01' AND '2016-12-31'
) tab1
Now I would have to add the 2017 year data - but if I just write FROM (SELECT ...) tab1, (SELECT ...) tab2 It will be a "cross prodcut" - And the numbers won't add up.