【发布时间】:2018-12-01 02:33:40
【问题描述】:
@status [nvarchar](max),
@fromDate [datetime],
@toDate [datetime],
@companyId [int]
select
ISNULL(SUM(rec.SubTotal), 0) AS SubTotal,
sto.Id AS StoreId,
CAST(rec.CreatedDate AS DATE) as CreatedDate,
sto.Name AS StoreName from Receipts rec
left join(
select ReceiptId, SUM(Quantity) as Quantity from ReceiptDetails
group by ReceiptId
) red on rec.Id = red.ReceiptId
left outer join(
select Id,Name from Stores
group by Id,Name
) sto on rec.StoreId = sto.Id
where rec.CompanyId = @companyId
and rec.Status = @status
and rec.CreatedDate <= @todate
and rec.CreatedDate >= @fromDate
group by sto.Id, sto.Name,CAST(rec.CreatedDate AS DATE)
这是我当前的查询 SQL,目前我在@todate 和 @fromdate 的 rangeDate 中选择每天的数据
现在我想按过去 7 周的日期按 CreatedDate 选择数据, @fromdate 为今天的示例:2018-12-1 预期的数据将是
2018-10-20
2018-10-27
2018-11-3
2018-11-10
2018-12-17
2018-11-24
2018-12-1
我目前的数据
...
...
2018-11-29
2018-11-30
2018-12-1
我指的是 6 周前的日期
【问题讨论】:
-
听起来像是
case ... when的问题。 -
这是什么意思:(
标签: sql sql-server