三个字段是:姓名、贡献、日期姓名是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
...........谢谢各位!
解决方案 »
- 哪位能帮忙将下面C语言转换成Delphi代码?
- 话说开帐号到现在有5个月了,刚刚步入5个三角,何时升星?
- Fast Report一个报表设计
- send里面的buf转换hex数据?
- 求:从一table向另一table插入语句!
- 麻烦进来看看我的问题。关于打砖块统计次数的。
- 关于fastreport2.4的一个小问题,在线等,,分不够可以加!!!!!!
- 谁能帮我把这个美眉解出来?
- DATASNAP对象的释放
- delphi 写一个post请求子程序,我想编译成dll,求大神帮忙.
- 本人的编程资源在线网站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