clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 809136 fiddles created (9800 in the last week).

CREATE TABLE movement (share_sale INTEGER, share_code VARCHAR(20), mvt_date DATETIME); INSERT INTO movement VALUES (100, '01254601144', '2018-05-08'); INSERT INTO movement VALUES (150, '01254601144', '2018-05-08'); INSERT INTO movement VALUES (137, '01254601144', '2018-05-08'); INSERT INTO movement VALUES (112, '01254601144', '2018-05-08'); INSERT INTO movement VALUES (190, '01254601144', '2018-05-07'); INSERT INTO movement VALUES (260, '01254601144', '2018-05-07'); INSERT INTO movement VALUES (121, '01254601144', '2018-05-07'); INSERT INTO movement VALUES (165, '01254601144', '2018-05-07'); INSERT INTO movement VALUES ( 95, '01254601144', '2018-05-06'); INSERT INTO movement VALUES (239, '01254601144', '2018-05-06'); INSERT INTO movement VALUES (120, '01254601144', '2018-05-06'); INSERT INTO movement VALUES (111, '01254601144', '2018-05-06'); INSERT INTO movement VALUES (222, '01254601144', '2018-05-06'); INSERT INTO movement VALUES ( 86, '01254601144', '2018-05-06'); INSERT INTO movement VALUES ( 75, '01254601144', '2018-05-05'); INSERT INTO movement VALUES ( 45, '01254601144', '2018-05-05'); INSERT INTO movement VALUES ( 98, '01254601144', '2018-05-05'); INSERT INTO movement VALUES (120, '01254601144', '2018-05-05'); INSERT INTO movement VALUES ( 67, '01254601144', '2018-05-05');
19 rows affected
 hidden batch(es)


WITH cte1 AS ( SELECT MIN(share_sale) AS min_sale, mvt_date AS min_mvt_date FROM movement GROUP BY mvt_date -- ORDER BY mvt_date ), cte2 AS ( SELECT MAX(share_sale) AS max_sale, mvt_date AS max_mvt_date FROM movement GROUP BY mvt_date -- ORDER BY mvt_date ), cte3 AS ( SELECT * FROM cte1 JOIN ( SELECT * FROM cte2 ) AS tab ON cte1.min_mvt_date = tab.max_mvt_date ) SELECT min_sale, max_sale, max_mvt_date FROM cte3
min_sale max_sale max_mvt_date
45 120 05/05/2018 00:00:00
86 239 06/05/2018 00:00:00
121 260 07/05/2018 00:00:00
100 150 08/05/2018 00:00:00
 hidden batch(es)