create table statistic (id int, date datetime, stat int) insert into statistic values…
- User
create table statistic (id int, date datetime, stat int) insert into statistic values (1, '2023-01-01', 100),(1, '2023-01-03', 100),(1, '2023-01-05', 100), (1, '2023-01-07', 150),(1, '2023-01-09', 150),(1, '2023-02-01', 150), (1, '2023-02-02', 100),(1, '2023-02-12', 100),(1, '2023-02-15', 100), (1, '2023-02-17', 150),(1, '2023-03-09', 150),(1, '2023-03-11', 150), (2, '2023-01-01', 100),(2, '2023-01-03', 100),(2, '2023-01-05', 100), (2, '2023-01-07', 150),(2, '2023-01-09', 150),(2, '2023-02-01', 150), (2, '2023-02-02', 100),(2, '2023-02-12', 100),(2, '2023-02-15', 100), (2, '2023-02-17', 150),(2, '2023-03-09', 150),(2, '2023-03-11', 150)
select id, date, stat from statistic bring information where change is happening
- Assistant
To select the rows where the change in "stat" is happening, you can use the following query:
sqlSELECT s1.id, s1.date, s1.stat FROM statistic s1 JOIN statistic s2 ON s1.id = s2.id AND s1.date = DATE_ADD(s2.date, INTERVAL -1 DAY) WHERE s1.stat != s2.statThis query uses a self-join to compare each row with the previous row. If the "stat" value is different, it means that the change is happening.