22,209
社区成员
发帖
与我相关
我的任务
分享
--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([营业时间] nvarchar(25),[物料代码] nvarchar(24),[名称] nvarchar(23),[数量] int)
Insert #T
select N'6月22日',N'N001',N'苹果',40 union all
select N'6月22日',N'N002',N'橘子',20 union all
select N'6月22日',N'N003',N'梨',60 union all
select N'6月22日',N'N001',N'苹果',20 union all
select N'6月22日',N'N004',N'西瓜',30 union all
select N'6月22日',N'N006',N'葡萄',50 union all
select N'6月22日',N'N009',N'哈密瓜',10 union all
select N'6月22日',N'N003',N'梨',15 union all
select N'6月22日',N'N002',N'橘子',38
Go
--测试数据结束
SELECT * ,
SUM([数量]) OVER ( PARTITION BY 营业时间, 物料代码, 名称 ) AS 今日总计
FROM #T;