我想使用当前客户 ID 执行子查询,因为我尝试在下面描述
SELECT DISTINCT Customer_Id,
(SELECT SUM (total) FROM Orders where Customer_Id = Customer_Id AND CAST(Date) > DayIspecify )
FROM Orders where shop_id= '1-9THT'
我想要的是计算每个客户在特定时间段内在特定商店花费的总和。
我想使用当前客户 ID 执行子查询,因为我尝试在下面描述
SELECT DISTINCT Customer_Id,
(SELECT SUM (total) FROM Orders where Customer_Id = Customer_Id AND CAST(Date) > DayIspecify )
FROM Orders where shop_id= '1-9THT'
我想要的是计算每个客户在特定时间段内在特定商店花费的总和。
SELECT Customer_Id, SUM(total) SumTotal
FROM Orders
where shop_id= '1-9THT'
group by Customer_id
不需要子查询试试这个:
SELECT Customer_Id,SUM(total)FROM Orders WHERE shop_id='1-9THT' GROUP BY Customer_Id
(更新)尝试:
select Customer_Id,
sum(case when o.shop_id = '1-9THT' and Date > DayIspecify
then total else 0 end) total
from Orders
group by Customer_Id
- 退回订单表中记录的所有客户,以及他们在指定日期之后通过商店 1-9THT 下达的任何订单的价值。(更改>
为>=
在指定日期或之后进行。)
SELECT DISTINCT Customer_Id, SUM (total) FROM Orders where shop_id= '1-9THT' group by customer_Id