当前位置:网站首页>mysql使用update联表更新的方法
mysql使用update联表更新的方法
2022-07-03 10:46:00 【追逐梦想永不停】
一、前言
之前在java代码里,分2步骤:
1.使用select查询一个结果集
2.根据这个结果集,使用update方法更新数据库
二、sql
现在需要不改动代码,用sql实现这个步骤,样例如下:
update a cs inner join
(
SELECT cs.class_id,cs.user_id FROM a cs,b ss
WHERE cs.class_id = ss.classid AND cs.user_id = ss.user_id
AND cs.isDel IS NULL
AND ss.num >=10
) rrr on cs.user_id=rrr.user_id and cs.class_id=rrr.class_id
set cs.type = '1';
说明:
1.sql里有一块,先查询出一个符合条件的结果集
2.然后更新a表,用符合条件的结果集里的数据,把符合条件的a表里的type改成1.
三、备注
还有一种方法,可以把符合条件的a表的id查询出来,然后更新a表的type时,根据id更新,使用多条update语句或者使用in语句都行。
边栏推荐
- Android log system
- Programmers' entrepreneurial trap: taking private jobs
- Application of high-precision indoor positioning technology in safety management of smart factory
- AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
- 软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
- The world's most popular font editor FontCreator tool
- DS90UB949
- 导师对帮助研究生顺利完成学业提出了20条劝告:第一,不要有度假休息的打算.....
- Kubernetes 三打探针及探针方式
- 一文搞懂Go语言Context
猜你喜欢
Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises
基于turtlebot3实现SLAM建图及自主导航仿真
高精度室内定位技术,在智慧工厂安全管理的应用
How to get started embedded future development direction of embedded
How should intermediate software designers prepare for the soft test
2022 northeast four provinces match VP record / supplementary questions
AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
Excel表格转到Word中,表格不超边缘纸张范围
Qt+VTK+OCCT读取IGES/STEP模型
Understand go language context in one article
随机推荐
JGG专刊征稿:时空组学
Static library vs shared library
R语言使用data.table包进行数据聚合统计计算滑动窗口统计值(Window Statistics)、计算滑动分组中位数(median)并合并生成的统计数据到原数据集中
Summary of interview questions (2) IO model, set, NiO principle, cache penetration, breakdown avalanche
Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
如何成为一名高级数字 IC 设计工程师(1-3)Verilog 编码语法篇:Verilog 行为级、寄存器传输级、门级(抽象级别)
软考中级软件设计师该怎么备考
R language ggplot2 visualization: gganimate package creates dynamic line graph animation (GIF) and uses transition_ The reveal function displays data step by step along a given dimension in the animat
Some common terms
CSRF
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
Touch and screen automatic rotation debugging
uniapp实现点击加载更多
After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
一些常用术语
phpcms 提示信息页面跳转showmessage
Bi skills - permission axis
Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3
uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
Technical experts from large factories: how can engineers improve their communication skills?