Mysql数据库SQL从一个表更新至另一个表

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;

相关推荐
Hello.Reader1 小时前
Redis 延迟监控深度指南
数据库·redis·缓存
ybq195133454311 小时前
Redis-主从复制-分布式系统
java·数据库·redis
好奇的菜鸟4 小时前
如何在IntelliJ IDEA中设置数据库连接全局共享
java·数据库·intellij-idea
tan180°4 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
满昕欢喜4 小时前
SQL Server从入门到项目实践(超值版)读书笔记 20
数据库·sql·sqlserver
DuelCode5 小时前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis
幽络源小助理5 小时前
SpringBoot基于Mysql的商业辅助决策系统设计与实现
java·vue.js·spring boot·后端·mysql·spring
Hello.Reader6 小时前
Redis 延迟排查与优化全攻略
数据库·redis·缓存
简佐义的博客7 小时前
破解非模式物种GO/KEGG注释难题
开发语言·数据库·后端·oracle·golang
爬山算法7 小时前
MySQL(116)如何监控负载均衡状态?
数据库·mysql·负载均衡