1、从一个表更新到另外一个表
方法一
UPDATE temp_x a, temp_y b SET a.`c_amount` = b.`c_amount` WHERE a.`c_id` = b.`c_id`;
方法二、
UPDATE temp_x a SET a.`c_amount` = (SELECT b.c_amount FROM temp_y b WHERE b.`c_id` = a.`c_id`)
2、多字段排序
if test="dto.mindSort!=null and dto.mindSort=='4'.toString()">
dict.sort ASC,reportStatus desc,
case reportDay
when '申请中' then '1'
when '长期可申报' then '2'
when '无需申报' then '3'
when '申报结束' then '4'
end asc
if>
3、获取当前时间的月份
select MONTH(DATE_SUB(CURDATE(),INTERVAL 1 MONTH)) from dual;
获取当前月份的上个月月份
DATE_SUB(CURDATE(),INTERVAL 1 MONTH)
4、表中有重复数据,如果去重查询数据
select a.* from taxation_data a join (select social_credit_code,max(base_id) best_history_data from taxation_data group by social_credit_code) b where a.social_credit_code=b.social_credit_code and a.base_id=b.best_history_data;