公司以前都是按自然月进行订单数量、金额的相关统计,现在财务要求统计时间由上个月的25号到下个月的24号为一个月进行统计。以前的方法如下:
orderID(订单ID) orderDate(订单时间) orderQty(数量) orderAmount(金额)
以前的查询都是YERA(orderDate),MONTH(orderDate),来进行分月统计,可是现在不能按这个自然月统计,该怎么做呢?
求解?
------解决方案--------------------
- SQL code
--财务专用的取年的函数create function Year_FICO(@sDate datetime)returns intasbegin if month(@sDate)=12 and day(@sDate)>=25 return year(@sDate)+1 return year(@sDate)end--财务专用的取月的函数create function Month_FICO(@sDate datetime)returns intasbegin if month(@sDate)=12 and day(@sDate)>=25 return 1 else if day(@sDate)>=25 return month(@sDate)+1 return month(@sDate)end