Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
156 views
in Technique[技术] by (71.8m points)

Reverse Cumulative Sum - MySQL

I have to perform a query that return the reverse cumulative sum with every stage that the client has passed, jumping the two firsts. The database register every customer that have been discarded and the stage that it happen.

This is my sample data:

CREATE TABLE descartados
(`stage` varchar(15), `date` datetime);

INSERT INTO descartados
(`stage`, `date`)
VALUES
('Entrada', '2021-01-18 13:03:36'),
('Filtro 2', '2021-01-11 19:40:47'),
('Filtro 2', '2021-01-11 13:28:54'),
('Filtro 2', '2021-01-11 19:44:16'),
('Entrada', '2021-01-11 13:28:24'),
('Entrada', '2021-01-11 13:29:28'),
('Entrada', '2021-01-11 18:17:26'),
('Filtro 2', '2021-01-11 19:40:22'),
('Entrada', '2021-01-11 18:35:32'),
('Filtro 2', '2021-01-11 18:40:27'),
('Entrada', '2021-01-12 17:49:03'),
('Filtro 2', '2021-01-12 17:19:15'),
('Entrada', '2021-01-12 12:37:41'),
('Entrada', '2021-01-12 18:17:38'),
('Entrada', '2021-01-13 12:12:27'),
('Entrada', '2021-01-13 12:13:00'),
('Entrada', '2021-01-12 19:00:05'),
('Filtro 1', '2021-01-18 12:48:21'),
('Entrada', '2021-01-12 17:52:18'),
('Entrada', '2021-01-13 12:13:53'),
('Entrada', '2021-01-13 12:43:28'),
('Entrada', '2021-01-13 13:13:11'),
('Entrada', '2021-01-13 13:15:13'),
('Agendados', '2021-01-13 13:15:13'),
('Qualificados', '2021-01-13 13:15:13'),
('Agendados', '2021-01-13 13:15:13'),
('Qualificados', '2021-01-13 13:15:13'),
('Agendados', '2021-01-13 13:15:13');

SELECT descartados.stage, descartados.date FROM descartados;
stage date
Filtro 2 2020-09-15 17:12:25
Entrada 2020-09-15 14:34:56
Entrada 2020-09-16 16:55:17
Filtro 1 2020-09-15 18:24:53
Entrada 2020-09-16 14:41:04
Entrada 2020-09-16 14:42:55
question from:https://stackoverflow.com/questions/65940005/reverse-cumulative-sum-mysql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...