Answer the question
In order to leave comments, you need to log in
How to find out the history of data changes using SQL query?
Hello.
There are two tables
CREATE TABLE links ([id] INTEGER PRIMARY KEY AUTOINCREMENT, [link_id] CHAR);
and
CREATE TABLE history_yap([id] INTEGER PRIMARY KEY AUTOINCREMENT, [link_id] INTEGER, [time] INTEGER, [value] INTEGER);
The first table stores the data, the second - the history of changes in certain parameters related to this data.
How can one query determine if there has been a data change?
For example:
in table 1 data
id=1
link_Id=123
in table 2 data:
1 123 1390444262 0
2 123 1390444263
1 the change was (at time 1390444262 it was 0, and at time 1390444263 it became 1).
Relevant for SqLite.
Thank you.
Answer the question
In order to leave comments, you need to log in
SELECT t.id, COUNT(*), SUM(t.ct)
FROM (SELECT l.id, y.value, COUNT(*) as ct
FROM links l
INNER JOIN history_yap y ON l.link_id = y.link_id
GROUP BY l.id, y.value) t
GROUP BY t.id
UNION ALL
SELECT l.id, -1, -1
FROM links l
LEFT JOIN history_yap y ON l.link_id = y.link_id
WHERE y.id IS NULL;
SELECT t.id, COUNT(*)
FROM (SELECT l.id, y.value
FROM links l
INNER JOIN history_yap y ON l.link_id = y.link_id
GROUP BY l.id, y.value) t
GROUP BY t.id
HAVING COUNT(*) > 1;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question