码迷,mamicode.com
首页 > 数据库 > 详细

mysql 常用语句整理

时间:2020-01-21 18:34:00      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:proc   step   www   sea   mysql   date   unit   st3   存在   

1. 替换某个字段中的部分内容

SET @oldlink1 = ‘http://192.168.100.66‘;
SET @newlink1 = ‘www.baidu.com‘;

UPDATE Test1
SET Content = (
	REPLACE (
		Content ,@oldlink1 ,@newlink1
	)
)
WHERE
	Content LIKE concat(‘%‘ ,@oldlink1, ‘%‘);

 

2.连表删除数据

SET @UnitId = ‘27542‘;

DELETE t1
FROM
	Test1 AS t1
INNER JOIN Test2 AS t2 ON t1.Code = t2.Code
WHERE
	t2.UnitId NOT IN (@UnitId);

  

3.连表插入数据

INSERT INTO Test (
	ID,
	PostTime
) SELECT
	UUID() AS ID,
	t1.PostTime
FROM
	Test1 AS t1
INNER JOIN Test2 AS t2 ON t1.Code = t2.Code;

 

4. 连表更新数据

UPDATE Test1 AS t1
INNER JOIN Test2 AS t2 ON t1.Code = t2.Code
SET t1.NextFlowNodeId = 72
WHERE
	t1.ProcessStepId = 70;

 

5.获取某个库下的所有表名

select table_name from information_schema.tables where table_schema=@dbName

  

6.获取某个表的所有字段名

select COLUMN_NAME from information_schema.COLUMNS where table_name = @tableName and table_schema = @dbName;

 

7.CONCAT 拼接字符串

SET @SearchText= CONCAT(‘%‘,‘测试‘,‘%‘);
SELECT * FROM  Test3 WHERE CONCAT(ItemName,ItemNumber,DeptName,RealName) LIKE @SearchText;

 注意:若拼接项中存在NULL值,结果为NULL。如 CONCAT(‘测试‘,‘001‘,NULL,‘小明‘),结果为NULL,并不是我们想要的结果:"测试001小明"

mysql 常用语句整理

标签:proc   step   www   sea   mysql   date   unit   st3   存在   

原文地址:https://www.cnblogs.com/zhuanjiao/p/12123058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!