update语句使用表中的字段更新

前言

有个表中的字段,需要从一张表字段更新到另外一张表

update语句

数据库表

sql 复制代码
/*
 Navicat Premium Dump SQL

 Source Server         : 192.168.69.46
 Source Server Type    : PostgreSQL
 Source Server Version : 150003 (150003)
 Source Host           : 192.168.69.46:65432
 Source Catalog        : luban
 Source Schema         : public

 Target Server Type    : PostgreSQL
 Target Server Version : 150003 (150003)
 File Encoding         : 65001

 Date: 19/06/2025 11:17:19
*/


-- ----------------------------
-- Table structure for device_apply
-- ----------------------------
DROP TABLE IF EXISTS "public"."device_apply";
CREATE TABLE "public"."device_apply" (
  "id" int8 NOT NULL,
  "create_id" int8,
  "create_time" timestamp(6),
  "dr" int4,
  "last_modify_id" int8,
  "last_modify_time" timestamp(6),
  "tenant_id" int8,
  "version" int4,
  "apply_status" int4,
  "approve_id" int8,
  "end_time" timestamp(6),
  "reason" varchar(255) COLLATE "pg_catalog"."default",
  "start_time" timestamp(6),
  "remark" varchar(255) COLLATE "pg_catalog"."default",
  "org_id" int8
)
;

-- ----------------------------
-- Table structure for device_apply_bind
-- ----------------------------
DROP TABLE IF EXISTS "public"."device_apply_bind";
CREATE TABLE "public"."device_apply_bind" (
  "id" int8 NOT NULL,
  "create_id" int8,
  "create_time" timestamp(6),
  "dr" int4,
  "last_modify_id" int8,
  "last_modify_time" timestamp(6),
  "tenant_id" int8,
  "version" int4,
  "device_apply_id" int8,
  "device_id" int8,
  "org_id" int8
)
;

-- ----------------------------
-- Primary Key structure for table device_apply
-- ----------------------------
ALTER TABLE "public"."device_apply" ADD CONSTRAINT "device_apply_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Primary Key structure for table device_apply_bind
-- ----------------------------
ALTER TABLE "public"."device_apply_bind" ADD CONSTRAINT "device_apply_bind_pkey" PRIMARY KEY ("id");

update语句写法

vbnet 复制代码
update device_apply set org_id = hello.org_id

  from (select b.device_apply_id as id, d.org_id as org_id from device_core d INNER JOIN device_apply_bind b on d.id = b.device_id) hello
  where device_apply."id" = hello."id"
相关推荐
赤龙ERP28 分钟前
ERP周报:连接器开闸、国产GPU进场与智能工厂253家
数据库·人工智能·大模型·rpa·erp·企业数字化·builderpattern
lusklusklusk35 分钟前
SQL Server补丁版本号为什么“日期新反而版本低”?——GDR、CU、CU+GDR 版本号规则与升级路径详解
数据库
key_3_feng1 小时前
评估与对齐:Agent 自我进化的护栏
前端·数据库·agent
TangGeeA1 小时前
数据库、SQL 与 DB AI
数据库·人工智能·sql
IvorySQL1 小时前
开源数据库进校园| 11 月 3 日,IvorySQL 校园行走进浙大宁波校区:从 PostgreSQL 扩展生态到 AI 实战
数据库·postgresql·开源
福建佰胜张工1 小时前
深度解析 Allen-Bradley 150-B135NBDA 智能电机控制器:选型、参数与工业应用
运维·数据库·单片机·嵌入式硬件·安全·自动化
`Levie1 小时前
MySQL-数据库服务日志管理与数据闪回
数据库·mysql
香蕉大香蕉(06敬畏市场)1 小时前
MySQL 单点详解(01)
java·数据库·mysql·面试·博客·实习
小小张说故事1 小时前
Python 的 str 为什么设计成不可变?拆开字符串驻留、字符串池,以及 += 拼接到底慢在哪
后端·python
LaughingZhu2 小时前
Product Hunt 热榜 2026-10-30:Empacer、Scape、Floot in ChatGPT
java·前端·数据库·人工智能·chatgpt·notion