add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tab1 (
`ID` VARCHAR(1),
`Trending_Date` VARCHAR(10),
`Views` INTEGER
);

INSERT INTO tab1
(`ID`, `Trending_Date`, `Views`)
VALUES
('A', '2021-01-03', '10'),
('B', '2020-10-30', '8'),
('A', '2021-02-05', '9'),
('B', '2020-11-02', '11');
SELECT ID,`Trending_Date`,`Views`
FROM
(SELECT ID,`Trending_Date`,
`Views` ,
LAG(`Views`, 1) OVER (
PARTITION BY `ID`
ORDER BY `Trending_Date`
) lastview
FROM tab1) t1
WHERE `Views` < lastview

ID Trending_Date Views
A 2021-02-05 9
SELECT ID,`Trending_Date`,`Views`
FROM
(SELECT
`Trending_Date`,
IF (@id <> ID,@views := 0,@views := @views) idchange,
IF (@views > `Views`,1,0) smaller,
@views := `Views` as Views,
@id := ID as ID
FROM tab1,(SELECT @views := 0,@id := '') t1
ORDER BY ID,`Trending_Date`) t2
WHERE smaller = 1;
ID Trending_Date Views
A 2021-02-05 9