搜索每月最后一天的纪录
select sum(storeamount) from cams_storeamount where month(writedate)=" + month + " and year(writedate)=" + year + " and day(writedate)=max(day(writedate))这样不行啊
writedate就是导入日期 --------------------编程问答-------------------- select sum(a.storeamount) from cams_storeamount a
inner join
{
select max(b.writedate) as writedate from cams_storeamount b where month(a.writedate)=month(b.writedate) and year(b.writedate)= year(b.writedate)
}
b on a.writedate=b.writedate
where month(a.writedate)=" + month + " and year(a.writedate)=" + year + "
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/ --------------------编程问答-------------------- 当然不能这样减啦,计算的话可以根据下个月的一号减于1天来计算:
--------------------编程问答-------------------- 忘了,有可能是跨年的,改进下:
string maxday=Convert.ToDateTime(Convert.ToString(writedate.Year)+"-"+Convert.ToString(writedate.Month+1)+"-1").AddDays(-1).Date.ToString();
string sql="select sum(storeamount) from cams_storeamount where month(writedate)=" + month + " and year(writedate)=" + year + " and day(writedate)="+ maxday +"";
--------------------编程问答-------------------- 同意一楼的做法,谢谢了 --------------------编程问答-------------------- 当然也可以用case判断月份的形式来写:
string maxday=Convert.ToDateTime(writedate.AddMonths(1).Year.ToString()+"-"+writedate.AddMonths(1).Month.ToString()+"-1").AddDays(-1).Date.ToString();
--------------------编程问答-------------------- 收藏...
string sql="select sum(storeamount) from cams_storeamount where month(writedate)=" + month + " and year(writedate)=" + year + " and day(writedate) = (case month(writedate) when 2 then 28 when 4 then 30 when 6 then 30 when 9 then 30 when 11 then 30 else 31 end)"
补充:.NET技术 , ASP.NET