当前位置: 首页 > news >正文

MYSQL 利用concat函数 生成更新或者插入SQL

有时候需要批量运维一批数据,一条一条写SQL比较麻烦,可以使用下面的方法批量生成select sales_order_number,a.sog_line_id,actual_price,sales_goods_unit_price,b.id,concat('update your_table set actual_price=', sales_goods_unit_price, ' where id=',b.id, ' and sog_line_id=', a.sog_line_id, ';', '-- ', sales_order_number) as updateSql
from table_a aleft join table_b b on a.sog_line_id = b.sog_line_id
where sales_order_number in ('');select so.sales_order_number,so.so_head_id,concat('INSERT INTO your_table (so_head_id, sog_line_id, sku_id,actual_price,item_discount,
unit_price,quantity, biz_id,currency,price_verification_status) VALUES (', so.so_head_id, ',', sog.sog_line_id, ',',sog.sales_goods_code, ',',sog.sales_goods_unit_price, ',', ifnull(sog.sales_goods_discount_price, 'null'), ',',ifnull(sog.sales_goods_unit_price, 'null'),',', 1, ',', 12, ',', '''USD''', ',', 0, ')', ';') as insertsql
from table_a sojoin table_b sog on so.so_head_id = sog.so_head_id
where sog.so_head_id in(xxxxxx, xxxxxx);

select sales_order_number,a.sog_line_id,actual_price,sales_goods_unit_price,b.id,concat('update your_table set actual_price=', sales_goods_unit_price, ' where id=',b.id, ' and sog_line_id=', a.sog_line_id, ';', '-- ', sales_order_number) as updateSql
from table_a aleft join table_b b on a.sog_line_id = b.sog_line_id
where sales_order_number in ('');select so.sales_order_number,so.so_head_id,concat('INSERT INTO your_table (so_head_id, sog_line_id, sku_id,actual_price,item_discount,
unit_price,quantity, biz_id,currency,price_verification_status) VALUES (', so.so_head_id, ',', sog.sog_line_id, ',',sog.sales_goods_code, ',',sog.sales_goods_unit_price, ',', ifnull(sog.sales_goods_discount_price, 'null'), ',',ifnull(sog.sales_goods_unit_price, 'null'),',', 1, ',', 12, ',', '''USD''', ',', 0, ')', ';') as insertsql
from table_a sojoin table_b sog on so.so_head_id = sog.so_head_id
where sog.so_head_id in(xxxxxx, xxxxxx);

concat怎么给查出来的字段加上单引号

在SQL中,CONCAT 函数通常用于将多个字符串连接成一个字符串。如果你需要给 CONCAT 的结果字段添加单引号,你可以在字段外部使用单引号来实现。

例如,假设你有一个名为 users 的表,其中包含 first_name 和 last_name 两个字段,你可以使用以下SQL语句来连接这两个字段,并在连接后的字符串两侧加上单引号:

SELECT CONCAT('\'', first_name, ' ', last_name, '\'') AS full_name FROM users;


http://www.mrgr.cn/news/80682.html

相关文章:

  • 公然上线传销项目,Web3 的底线已经被无限突破
  • 关闭浏览器安全dns解决访问速度慢的问题
  • Django开发入门 – 4.创建Django app
  • 【黑马点评】 使用RabbitMQ实现消息队列——3.批量获取1k个用户token,使用jmeter压力测试
  • 深入理解Java对接DeepSeek
  • 1.【线性代数】——方程组的几何解释
  • HUAWEI-eNSP交换机链路聚合(手动负载分担模式)
  • go 自己写序列化函数不转义
  • linux安装mysql
  • 二、使用langchain搭建RAG:金融问答机器人--数据清洗和切片
  • Python 在Word文档中插入图片的3种方式(插入到段落、插入到指定位置、插入到每一页)
  • spring\strust\springboot\isp前后端那些事儿
  • 三、使用langchain搭建RAG:金融问答机器人--检索增强生成
  • iClient3D for Cesium 实现限高分析
  • 【Nginx-4】Nginx负载均衡策略详解
  • 阮一峰C语言教程_10字符串
  • 最新ubuntu20.04安装docker流畅教程
  • 数据结构十大排序之(冒泡,快排,并归)
  • 【济大期末数据库】SQL语法速成
  • 跟着AI 学AI开发二,本地部署自己的Chat GPT
  • 解决新安装CentOS 7系统mirrorlist.centos.org can‘t resolve问题
  • NLP-Huggingface基本使用方法
  • 网络攻与防
  • Javascript面试手撕常见题目(回顾一)
  • linux centos 7 安装 mongodb7
  • vue字母划分选择城市组件(国内国际)