zaytanie po dacie

Przed

SELECT
    MONTH(o.created_at) AS month,
    COUNT(1) AS 'total in month',
    ((SELECT COUNT(1) FROM `order` AS o1 FORCE INDEX (idx_created_at) WHERE o1.customer_id IS NOT NULL AND MONTH(o1.created_at) = MONTH(o.created_at) AND YEAR(o1.created_at) = 2020) / COUNT(1)) * 100 AS '% logged in',
    ((SELECT COUNT(1) FROM `order` AS o1 FORCE INDEX (idx_created_at) WHERE o1.customer_id IS NULL AND MONTH(o1.created_at) = MONTH(o.created_at) AND YEAR(o1.created_at) = 2020) / COUNT(1)) * 100 AS '% guests'
FROM `order` AS o
FORCE INDEX (idx_created_at)
WHERE YEAR(o.created_at) = 2020
GROUP BY MONTH(o.created_at);

Po

SELECT
    MONTH(o.created_at) AS month,
    COUNT(1) AS 'total in month',
    ((SELECT COUNT(1) FROM `order` AS o1 FORCE INDEX (idx_created_at) WHERE o1.customer_id IS NOT NULL AND MONTH(o1.created_at) = MONTH(o.created_at) AND YEAR(o1.created_at) = 2020) / COUNT(1)) * 100 AS '% logged in',
    ((SELECT COUNT(1) FROM `order` AS o1 FORCE INDEX (idx_created_at) WHERE o1.customer_id IS NULL AND MONTH(o1.created_at) = MONTH(o.created_at) AND YEAR(o1.created_at) = 2020) / COUNT(1)) * 100 AS '% guests'
FROM `order` AS o
FORCE INDEX (idx_created_at)
WHERE YEAR(o.created_at) = 2020
GROUP BY MONTH(o.created_at);

 

Komentarze wyłączone