三个字段是:姓名、贡献、日期姓名是CHAR(N)
贡献是Integer
日期是Date我怎么用一条SQL列出每个人在这个月和今天的贡献总和!每个人每天都会添加若干条记录如:
AAA 50 2004-7-10
AAA 20 2004-7-10
BBB 40 2004-7-10
AAA 20 2004-7-10
CCC 20 2004-7-1
...........谢谢各位!
贡献是Integer
日期是Date我怎么用一条SQL列出每个人在这个月和今天的贡献总和!每个人每天都会添加若干条记录如:
AAA 50 2004-7-10
AAA 20 2004-7-10
BBB 40 2004-7-10
AAA 20 2004-7-10
CCC 20 2004-7-1
...........谢谢各位!
解决方案 »
- 请教:关于用DELPHI开发一个ActiveX组件的问题!!!
- 软件出错,软件不能运行,出错提示见内容
- 寻delphi编程高手,南京
- 如何用wm_command发送命令点击另一程序按钮???????????
- Need your Help!
- 如何判断一个字符串是否是日期?在线,马上给分。
- 我想找有关flash控件的资料,希望有人帮我:),谢谢!
- 我点击DBNavigator的提交后数据仍未保存,为什么?
- -=-=-用户输入两个日期(用DateTimePickker),怎么判断它们的先后顺序呢?很急!-=-=-
- delphi7+sql2000开发的cs进销存程序,如何更改为云存储?
- 本人的编程资源在线网站www.delphi163.com开通,高兴,散分,来者有分
- 如何将查询到的数据集转化为gzip文件??
select name,sum(gongxian) from table1 where aDate = (select getdate()) group by name
这个月
select name,sum(gongxian) from table1 where MonthOf(aDate) = MonthOf(select getdate()) group by name
select name,count(gongxian) from table1 where aDate = (select getdate()) group by name.
我的意思是只想用一条语句,而不是分开罗列
最好能成为车个样子Name Today Month
AAA 90 90
BBB 40 40
CCC 0 20谢谢大家!
(
name varchar(10),
gongxian integer,
date datetime
)select a.name,isnull(b.today,0) as today,c.Month
from
(
select distinct name from
)a
left join
(
select name,sum(gongxian) as Today
from
where year(date)=year(getdate())
and month(date)=month(getdate())
and day(date)=day(getdate())
group by name
)b
on a.name=b.name
left JOIN
(
select name,sum(gongxian) as Month
from
group by .name,month(.date)
)c
on a.name=c.name
select a.name,a.mmgx,b.ddgx from
(select name,sum(gx) as mmgx from character where datepart(mm,mdate)=datepart(mm,getdate()) group by name) a,
(select name,sum(gx) as ddgx from character where datepart(dd,mdate)=datepart(dd,getdate()) group by name) b
where a.name=b.name
Select Name,
Sum(Case When Date = (select getdate()) then gongxian end) as today,
Sum(Case When Month(Date)=(Month(select getdate()) then gongxian end)as Month
From table1
Group by Name