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. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-26 19:16:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-26 19:16:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-26 19:16:03       82 阅读
  4. Python语言-面向对象

    2024-03-26 19:16:03       91 阅读

热门阅读

  1. RCC时钟代码详解<一步一注释>

    2024-03-26 19:16:03       42 阅读
  2. LEETCODE-DAY28

    2024-03-26 19:16:03       39 阅读
  3. 网络安全知识核心之RIP的工作原理

    2024-03-26 19:16:03       38 阅读
  4. Windows与Linux端口占用查看、杀死的方法

    2024-03-26 19:16:03       33 阅读
  5. # 15 React 使用useEffect获取网络数据

    2024-03-26 19:16:03       45 阅读
  6. C++中string容器的元素访问

    2024-03-26 19:16:03       44 阅读
  7. 6. C++ 内存分布

    2024-03-26 19:16:03       35 阅读
  8. 大数据中TopK问题

    2024-03-26 19:16:03       38 阅读
  9. vue中动态路由是什么该如何实现

    2024-03-26 19:16:03       44 阅读
  10. Dockerfile, nginx.conf文件解读

    2024-03-26 19:16:03       39 阅读