如何计算每天的总和 [英] How to calculate the sum per day

查看:117
本文介绍了如何计算每天的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI



我目前正在为我的客户创建报告,并想知道如何计算用户处理的记录数量每天。





我的桌子是Stage1





id(int),product(Nvarchar),date(datetime),userid(int),stage(int)



我的查询是什么选择用户输入的产品数量?



i需要获得用户每天通过的产品数量



选择Sum(userid),Workcompleted from Table group by workcompleted

HI

I am currently creating a report for my client and would like to know how would i be able to calculate the amount of records processed by a user for each day.


My table is Stage1


id(int),product(Nvarchar),date(datetime),userid(int),stage(int)

what would my query be to select the amount of products entered by a user?

i need to get the count of products passed per day by a user

Select Sum(userid),Workcompleted from Table group by workcompleted

推荐答案

Select Sum(Workcompleted ) from Table where userid = @userid 





会做它,假设workcompleted是r的数量ecords处理



如果你只是想记录那么记录





would do it, assuming workcompleted is the number of records processed

if you just want to counmt the records then

select count(*) from Table where userId = @userId


尝试下面的T-SQL代码:



try below T-SQL code :

CREATE TABLE #TEMP
(
	ITEM	VARCHAR(50),
	AMOUNT	INT,
	INDATE  DATETIME,
	USERID	INT
)

INSERT INTO #TEMP VALUES('WATCH',500,'02/13/2013',1)
INSERT INTO #TEMP VALUES('BELT',300,'02/13/2013',1)
INSERT INTO #TEMP VALUES('WALLET',600,'02/13/2013',2)
INSERT INTO #TEMP VALUES('TROUSERS',1600,'02/13/2013',2)

SELECT USERID,INDATE,SUM(AMOUNT) AS TOTALAMOUNT
FROM #TEMP
GROUP BY USERID,INDATE

DROP TABLE #TEMP


选择sum(amt),来自tablex的id,其中date =''2012-10-10''和id = 1 group by id
select sum(amt),id from tablex where date=''2012-10-10'' and id= 1 group by id


这篇关于如何计算每天的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆