0

我想使用当前客户 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' 

我想要的是计算每个客户在特定时间段内在特定商店花费的总和。

4

4 回答 4

4
SELECT Customer_Id, SUM(total) SumTotal
FROM Orders
where shop_id= '1-9THT' 
group by Customer_id
于 2013-04-24T10:35:26.760 回答
2

不需要子查询试试这个:

SELECT Customer_Id,SUM(total)FROM Orders WHERE shop_id='1-9THT' GROUP BY Customer_Id
于 2013-04-24T10:37:17.690 回答
1

(更新)尝试:

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 下达的任何订单的价值。(更改>>=在指定日期或之后进行。)

于 2013-04-24T10:44:30.140 回答
0

使用SQL GroupBy

SELECT DISTINCT  Customer_Id,  SUM  (total) FROM Orders  where shop_id= '1-9THT' group by customer_Id
于 2013-04-24T10:37:19.323 回答