select nvl(sum(order_ticket_num),0)
from crs_order c
left join crs_order_contact cc
on c.id_order = cc.id_order
where cc.openid = #{openid,jdbcType=VARCHAR}
and c.tm_update >
to_date((to_char(trunc(sysdate, 'year') - 1, 'yyyy') ||
'-12-31 23:59:59'),
'yyyy-mm-dd hh24:mi:ss')
and c.tm_update <= sysdate
and c.is_del = 0
and c.order_status != 10021030
and c.order_status != 10021040
and cc.is_del = 0
and c.product_type='10271010'
and c.source_code = #{sourceCode,jdbcType=VARCHAR}
用的oracle数据库,以当前系统时间为参数,取表里时间字段大于上一年12月31日23:59:59秒并且小于当前系统时间的值 就是自然年内的数据。 如果测试不通过,则麻烦校对一下 线上库之间的系统时间 是否一致