Answer the question
In order to leave comments, you need to log in
How to compose sql?
Tell me how to do it? already broke the whole brain
[data ] there is a table with data
id | value | year | month | day | hour ...
[ lastadata ] there is a table with data that has already been checked and it contains the id of the last checked record
id | id_data
how to get the data and if there is no data, then get the last checked ones instead,
for example
[data]
1 | 120 | 2015 | 12 | 10 | 2 |
2 | 121 | 2015 | 12 | 10 | 3 |
3 | 122 | 2015 | 12 | 10 | 4 |
4 | 122 | 2015 | 12 | 10 | 5 |
[lastdata]
1 | 2 <- link
As a result, get
120 | 2015 | 12 | 10 | 2 |
121 | 2015 | 12 | 10 | 3 |
122 | 2015 | 12 | 10 | 4 |
121 | 2015 | 12 | 10 | 3 |
122 | 2015 | 12 | 10 | 5 |
simple examples
SELECT * FROM data WHERE year=<...> AND mont=<...> AND day = <...>
SELECT * FROM lastdata LEFT JOIN data ON data.id = lastdata.id_data WHERE <...>
Answer the question
In order to leave comments, you need to log in
As I understand from the last example, you just need to add the lust_update field to the table, the default TIMESTAMP type is CURRENT_TIMESTAMP with the on update attribute. And update the same table row. And you will see how many apples the user has and when he will last inform you about it.
It is suitable? or do you need to save the history of changes in the number of apples from the user?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question