我有一个包含以下列的表格:
Amount;
Discount;
Timestamp (UTC) with two years 2016/2017;
Order_ID;
Customer_ID
现在,我想获取一个唯一客户列表以及新客户(以前从未交易过),每月在2016年1月至2017年2月之间,但要按我所在的时区(即IST而不是UTC)
我已经编写了以下代码,以每月获得唯一客户,但无法理解如何合并计数(新客户)和同时更改时区
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;