我正在尝试计算在线商店客户的积分使用情况。随着时间的推移,客户获得积分。当积分被兑换时,customer.points的值被修改以反映剩余要兑换的积分。获得的任何额外积分也会添加到customer.points中。因此,确定客户在帐户生命周期内获得的积分数量的唯一真正机制是将总使用量与剩余积分相加(order
.total + customer.points)。
下面的查询返回所需的结果,但仅适用于已兑换积分的客户。我想要的是,因为所有客户都有积分,所以也能够为那些没有兑换积分的人返还积分余额。
SELECT customer.store_id, customer.customer_id, `order`.total + customer.points
AS allpoints, customer.firstname, customer.lastname
FROM `order`
INNER JOIN customer ON `order`.customer_id = customer.customer_id
WHERE (customer.store_id =3)
GROUP BY customer.customer_id