You are on page 1of 1

1.

SELECT *
FROM (
SELECT
C.*,
SUM(T.transaction_amount) AS transaction_amount_inr
FROM
customer C
JOIN
transaction T ON C.customerid = T.customerid
GROUP BY
C.customerid, C.customername, C.birth_day
ORDER BY
transaction_amount_inr DESC
)
WHERE ROWNUM <= 5;

2.

YTD - From 1st April of current year

SELECT
COUNT(DISTINCT customerid) AS ytd_count
FROM
transaction
WHERE
transactiondate >= '01-04-2023';

CMCY - Current Month and Current Year

SELECT COUNT(DISTINCT customerid) AS cmcy_customer_count


FROM customer
WHERE YEAR(transactiondate) = YEAR(NOW()) AND MONTH(transactiondate) =
MONTH(NOW());

CMLY - Current Month and Last Year

SELECT COUNT(DISTINCT customerid) AS cmly_customer_count


FROM customer
WHERE YEAR(transactiondate) = YEAR(NOW()) - 1 AND MONTH(transactiondate) =
MONTH(NOW());

LYTD - YTD of last year

SELECT DISTINCT customerid


FROM customer
WHERE transactiondate >= DATE_FORMAT(NOW() - INTERVAL 1 YEAR, '%Y-04-01')
AND transactiondate < DATE_FORMAT(NOW(), '%Y-04-01');

3.

You might also like