I have a table with following columns:
Amount;
Discount;
Timestamp (UTC) with two years 2016/2017;
Order_ID;
Customer_ID
Now I want to get a list of unique customers along with new customers (who have never transacted before) per month between Jan-2016 and Feb-2017 but as per my local time zone i.e. IST and not UTC
I have written the below code to get unique customers per month but not able to understand how to incorporate count(new customers) and change time zone simultaneously
SELECT SUM(Amount) AS total,
SUM(discount) AS tdisc,
YEAR(timestamp) AS yyyy,
MONTH(timestamp) AS mm,
COUNT(order_id),
COUNT(DISTINCT(customer_id)) AS distcid
FROM table t
GROUP BY YEAR(timestamp),
MONTH(timestamp)
HAVING YEAR(timestamp) >= 2016 AND
YEAR(timestamp) < 2017
ORDER BY timestamp;