『壹』 在資料庫中如何查詢當天的數據
以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