select col_name,sum(case when day([date])='02' then col_int end) as col_DD,
sum(case when month([date])='07' then col_int end) as col_mm,
sum(case when year([date])='2003' then col_int end) as col_yy
from tbl_1
group by col_name
sum(case when month([date])='07' then col_int end) as col_mm,
sum(case when year([date])='2003' then col_int end) as col_yy
from tbl_1
group by col_name
解决方案 »
- 收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 请问怎么把加密过的存储过程打包到安装程序中?
- 如何将sql中的数据库中的某数据表导进access数据库中去?
- |zyciis| 急 国外买了一个SQL2008的数据库空间,但是我插入的数据的时候中文全变成了"???"
- 请问为什么我的数据存不进去?
- 时间数据的格式化
- 求教,这个结果应该怎么写sql语句
- 急问:误Delete了后如何恢复数据
- 怎样把客户端的文本数据批量导入到服务器上的sqlserver某张表里
- 变量
- 求一SQL语句,急
- 在线等:SQL SERVER6.5与XML、2000与6.5之间问题啊!!!!???
- 我想给某个表的每一个字段设置一个中文的名字,以便在程序的界面上用作标签?如何实现?
sum(case when datediff(day,[date],'2002/07/02')=0 then col_int end) [col_DD(日)],
sum(case when datediff(month,[date],'2002/07/02')=0 then col_int end) [col_MM(当月)],
sum(case when datediff(year,[date],'2002/07/02')=0 then col_int end) [col_YY(当年)]
from Tbl_1 group by [col_name]
count('col_MM(当月)') as 'col_DD(日)',
count('col_YY(当年)') as 'col_MM(当月)',
count(*) as 'col_YY(当年)'
from 表
where [date]='2002/07/02'
group by Col_name,datepart(yy,[date])
sum(case when datediff(day,[date],'2002/07/02')=0 then col_int else 0 end) [col_DD(日)],
sum(case when datediff(month,[date],'2002/07/02')=0 then col_int else 0 end) [col_MM(当月)],
sum(case when datediff(year,[date],'2002/07/02')=0 then col_int else 0 end) [col_YY(当年)]
from Tbl_1 group by [col_name]
(select sum(col_int) from Tbl_1 where datediff(day,date,getdate()) = 0) AS col_dd,
(select sum(col_int) from Tbl_1 where datediff(day,date,getdate()) = 0) AS col_mm,
(select sum(col_int) from Tbl_1 where datediff(day,date,getdate()) = 0) AS col_yy
from Tbl_1 group by col_name
set @edate = '2002-7-2'
select col_name, sum(col_int) [col_DD(日)],
(select sum(col_int) from tbl_1 where col_name = A.col_name and datediff(month,@edate, [date]) = 0) [col_MM(当月)],
(select sum(col_int) from tbl_1 where col_name = A.col_name and datediff(year,@edate, [date]) = 0) [col_YY(当年)]
from from tbl_1 A
where [date] = @edate
group by col_name
sum(case when date='2002/07/02' then col_int end) as col_DD(日),
sum(case when datediff(month,[date],'2002/07/02')='0' then col_int end) as col_MM(当月),
sum(case when datediff(year,[date],'2002/07/02')='0' then col_int end) as col_YY(当年)
from Tbl_1 group by col_name
Col_DD=Select Sum(Col_Int) from tb1_1 where Substring(Date,1,4)='2003' from Tb1_1
order by col_name
(select sum(col_int) from Tbl_1 where datediff(day,date,getdate()) = 0) AS col_dd,
(select sum(col_int) from Tbl_1 where datediff(month,date,getdate()) = 0) AS col_mm,
(select sum(col_int) from Tbl_1 where datediff(year,date,getdate()) = 0) AS col_yy
from Tbl_1 group by col_name
(select sum(col_int) from Tb1_1 a where datepart(mm,a.date)=datepart(mm,b.date) and a.col_name=b.col_name) as col_MM,
(select sum(col_int) from Tb1_1 c where datepart(yy,c.date)=datepart(yy,b.date) and c.col_name=b.col_name) as col_YY
from Tb1_1 b group by col_name,date having date='2002/07/02'
(select sum(col_int) from Tb1_1 a where datepart(mm,a.date)=datepart(mm,b.date) and a.col_name=b.col_name) as [col_MM(当月)],
(select sum(col_int) from Tb1_1 c where datepart(yy,c.date)=datepart(yy,b.date) and c.col_name=b.col_name) as [col_YY(当年)]
from Tb1_1 b group by col_name,date having date='2002/07/02'
sum(case when datediff(day,[date],'2002/07/02')=0 then col_int end) [col_DD(日)],
sum(case when datediff(month,[date],'2002/07/02')=0 then col_int end) [col_MM(当月)],
sum(case when datediff(year,[date],'2002/07/02')=0 then col_int end) [col_YY(当年)]
from Tbl_1 group by [col_name]