‘壹’ 在数据库中如何查询当天的数据
以sqlserver为例,假设日期字段为saledate,则当天sql如下:
select * from [LHDDXkms].[dbo].
[ST_ PPTN _ R ] where STCD =60432099
and DateDiff(dd,saledate,getdate())=0
其他日期,变更最后的and后面即可。
昨天:and DateDiff(dd,saledate,getdate())=1
一周:and DateDiff(dd,saledate,getdate())<=7
一月:and DateDiff(mm,saledate,getdate())=0
‘贰’ 数据库查询某月每天的数据量
set@x:=0;
selectpdays.pday,sum(t.money)
from
(selectpdayfrom
(selectadddate(str_to_date('2013-09-01','%Y-%m-%d'),f1)aspday
from(select@x:=@x+1asf1fromcustomerlimit1,31)t1
)t2wherepday<=last_day(str_to_date('2013-09-01','%Y-%m-%d'))
)pdays
leftjoin销售表tonpdays.pday=t.date
wheret.name='fff'
groupbypdays.pday