By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tablename (`DATETIME` DATETIME, `CLIENTS` INTEGER);
INSERT INTO tablename (`DATETIME`, `CLIENTS`) VALUES
('2018-03-03 08:00:00', '1'),
('2018-03-03 09:00:00', '2'),
('2018-03-03 10:00:00', '3'),
('2018-03-03 11:00:00', '4'),
('2018-03-03 12:00:00', '5'),
('2018-03-03 13:00:00', '3'),
('2018-03-03 14:00:00', '4'),
('2018-03-03 15:00:00', '5');
select
sum(case when clients > prev then clients - prev end) total
from (
select *, lag(clients, 1, 0) over (order by datetime) prev
from tablename
where date(datetime) = '2018-03-03'
) t
total |
---|
7 |