求mysql 时间段的信用值

今天同事遇到一个求时间段的信用值统计,让我花几分钟写出来,不从效率上考虑.基本上是可以实现。为了方便自已记忆,就记录下来
select sum(a1),sum(a2) from (
select if(to_days(now())-to_days(ltime)<7,1,0) as a1,if
(to_days(now())-to_days(ltime)<30,1,0) as a2,appraise
from leaveword_po
) as ttt
group by appraise


你可能感兴趣的:(mysql)