借款公司 银行名称 借款金额 借款日期 到期日 当月计息天数
a 中国银行 200 2012-11-1 2013-11-1 31
a 中国银行 200 2012-12-5 2012-12-25 21
a 中国银行 200 2012-12-15 2013-12-10 16
a 中国银行 200 2012-10-5 2012-12-20 20
a 中国银行 200 2011-10-1 2012-10-1 0
a 中国银行 200 2013-1-1 2013-6-30 0
针对以上6种情况的判断,估计要用到存诸过程,因为是新手,不知如何写详细代码? 作者: 乐堂-莫莫 时间: 2013-3-19 11:00
if(到期日>借款日期)
then select datediff(day,到期日,借款日期) day into a;
else
a=0作者: 乐堂-莫莫 时间: 2013-3-19 11:01
还要加个1.作者: xoyo5460 时间: 2013-3-20 09:41
这里的关键是由用户输入要查询的起讫日期,根据输入的日期区间来和数据表中的借款日、到期日的区间进行判断,不是简单的将数据表中的两个日期进行比较的。作者: 蓝寅舞九天 时间: 2013-7-14 12:55
假设借款日期 是date1,到期日date2;
SELECT
case when
datediff(
case when date2<='2012-12-31' then date2 else '2012-12-31' end,
case when date1>='2012-12-01' then date1 else '2012-12-01' end
)
<-1
then 0
else
datediff(
case when date2<='2012-12-31' then date2 else '2012-12-31' end,
case when date1>='2012-12-01' then date1 else '2012-12-01' end
)+1
end
FROM table t
;