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;

相关推荐
陈皮糖..1 小时前
27 届运维实习笔记|第三、四周:从流程熟练到故障排查,企业运维实战深化
运维·笔记·sql·nginx·ci/cd·云计算·jenkins
weixin_520649871 小时前
数据库函数
数据库
Bert.Cai2 小时前
MySQL LPAD()函数详解
数据库·mysql
OnlyEasyCode3 小时前
Navicat 任务自动备份指定数据库
数据库
if else3 小时前
Redis 哨兵集群部署方案
数据库·redis
yejqvow123 小时前
Pandas 高效实现组内跨行时间戳匹配与布尔标记
jvm·数据库·python
了不起的云计算V4 小时前
从DeepSeek V4适配看国产算力的三个拐点
数据库·人工智能
qq_189807034 小时前
html标签如何提升可访问性_aria-label与title区别【指南】
jvm·数据库·python
norq juox4 小时前
MySQL 导出数据
数据库·mysql·adb
qq_349317484 小时前
mysql如何设置定时自动备份脚本_编写shell脚本与cron任务
jvm·数据库·python