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;

相关推荐
闪电悠米7 分钟前
黑马点评-秒杀优化-03_blocking_queue_async_order
数据库·分布式·oracle·junit·wpf·lua
Python私教11 分钟前
免费用上 GPT-4 级模型:国产大模型 API 接入教程(2026 最新版)
数据库
星空椰15 分钟前
Tauri 开发模式下 SQLite 数据库文件变更导致应用自动重启问题
数据库·sqlite·tauri
不会就选b9 小时前
MySQL之视图
数据库·mysql
>no problem<9 小时前
基于cola5.0的基础设施层的多数据库切换方案思路
数据库·spring boot·mybatisplus·cola5.0·数据库迁移适配
OceanBase数据库官方博客9 小时前
OceanBase 赋能央国企:从发电到用电的全链路业务承载
数据库·oceanbase
瀚高PG实验室10 小时前
pgsql-ogr-fdw
数据库·postgresql·瀚高数据库·highgo
IvorySQL10 小时前
PostgreSQL 技术日报 (6月5日)|PG19 Beta1 上线,PGConf.PL 2026开启征稿
数据库·postgresql·区块链
abcy07121311 小时前
pycharm python sqlalchemy mysql增删改查实例csdn
数据库·oracle
无风听海11 小时前
IndexedDB 深度指南 浏览器中的事务型对象数据库
前端·数据库