我希望订单总额和总收入在31月12日。但是在这个查询中有很多重复的值..
select *
from Orderdetails od inner join
OrderProducts op
on od.orderid=op.orderid inner join
addonProducts ap
on ap.addonproductid=op.productid
where od.DeliveryDate between convert(datetime,Convert(varchar(50), '12/31/2014',101)) and
convert(datetime, Convert(varchar(50), '01/02/2015',101)) and
Datepart(Month, od.DeliveryDate) = '12' and DATEPART(DAY,od.DeliveryDate) = '31' and
od.TransactionId is not null and ap.addonCategoryId='1002'
答案 0 :(得分:0)
在没有任何架构细节的情况下:
select count(distinct od.transactionId), sum(op.productprice)
from Orderdetails od inner join
OrderProducts op
on od.orderid=op.orderid inner join
addonProducts ap
on ap.addonproductid=op.productid
where od.DeliveryDate between '2014-12-31' and '2015-01-01'and
od.TransactionId is not null and ap.addonCategoryId='1002'
这将为您提供当天的订单总额和收入假设: