SELECT
    DATE(created_at) AS Date,
    SUM(CASE WHEN type = 1 THEN 1 ELSE 0 END) AS Hourly_Sent,
    SUM(CASE WHEN type = 1 THEN is_open ELSE 0 END) AS Hourly_Open,
    SUM(CASE WHEN type = 2 THEN 1 ELSE 0 END) AS 2_Days_Sent,
    SUM(CASE WHEN type = 2 THEN is_open ELSE 0 END) AS 2_Days_Open,
    SUM(CASE WHEN type = 3 THEN 1 ELSE 0 END) AS 4_Days_Sent,
    SUM(CASE WHEN type = 3 THEN is_open ELSE 0 END) AS 4_Days_Open
FROM abandoned_cart_logs
WHERE DATE(created_at) >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
AND DATE(created_at) < CURDATE()
GROUP BY DATE(created_at)
UNION ALL
SELECT
    'Totals' AS Date,
    SUM(CASE WHEN type = 1 THEN 1 ELSE 0 END) AS Hourly_Sent,
    SUM(CASE WHEN type = 1 THEN is_open ELSE 0 END) AS Hourly_Open,
    SUM(CASE WHEN type = 2 THEN 1 ELSE 0 END) AS 2_Days_Sent,
    SUM(CASE WHEN type = 2 THEN is_open ELSE 0 END) AS 2_Days_Open,
    SUM(CASE WHEN type = 3 THEN 1 ELSE 0 END) AS 4_Days_Sent,
    SUM(CASE WHEN type = 3 THEN is_open ELSE 0 END) AS 4_Days_Open
FROM abandoned_cart_logs
WHERE DATE(created_at) >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
AND DATE(created_at) < CURDATE();