1、替换字段操作replace

update `news` SET `content`=replace(content,'data-src','src')

update wanyi2018 set path = SUBSTRING(path,18,3000)   从第18个开始替换


CONCAT(s1,s2,...)返回连接参数产生的字符串,一个或多个待拼接的内容,任意一个为NULL则返回值为NULL。
CONCAT_WS(x,s1,s2,...)返回多个字符串拼接之后的字符串,每个字符串之间有一个x。
SUBSTRING(s,n,len)、MID(s,n,len)两个函数作用相同,从字符串s中返回一个第n个字符开始、长度为len的字符串。
LEFT(s,n)、RIGHT(s,n)前者返回字符串s从最左边开始的n个字符,后者返回字符串s从最右边开始的n个字符。
INSERT(s1,x,len,s2)返回字符串s1,其子字符串起始于位置x,被字符串s2取代len个字符。
REPLACE(s,s1,s2)返回一个字符串,用字符串s2替代字符串s中所有的字符串s1。
LOCATE(str1,str)、POSITION(str1 IN str)、INSTR(str,str1)三个函数作用相同,返回子字符串str1在字符串str中的开始位置(从第几个字符开始)。
FIELD(s,s1,s2,...)返回第一个与字符串s匹配的字符串的位置。

2、将两个个字段或者多个字段合并一起输出concat

select concat (id, name, score) as info from tt2;

update table set C = concat (A,B) where

concat_ws(‘分隔符’, str1, str2, ...)可建立分隔符进拼装

此功能强大,如果用到其他类似情况可以百度搜详尽资料

3、Mysql update多表联合更新

1. 执行 UPDATE student s , class c SET s.class_name='test00',c.stu_name='test00' WHERE s.class_id = c.id

2. 执行 UPDATE student s JOIN class c ON s.class_id = c.id SET s.class_name='test11',c.stu_name='test11'

3. 执行 UPDATE student s LEFT JOIN class c ON s.class_id = c.id SET s.class_name='test22',c.stu_name='test22'

4. 执行 UPDATE student s RIGHT JOIN class c ON s.class_id = c.id SET s.class_name='test33',c.stu_name='test33'

5. 执行 UPDATE student s JOIN class c ON s.class_id = c.id SET s.class_name=c.name , c.stu_name=s.name

4、查两个表

select Emp.E_Id,Company.C_OraName from Emp,Company where Companey.C_Id=Emp.C_Id


5、查表中某个字段有多少种值

SELECT DISTINCT 列名称 FROM 表名称

6、筛选数据库的电话号码

SELECT * FROM kehu WHERE mobile REGEXP "^[1][35678][0-9]{9}$" AND mobile ORDER BY mobile DESC







7、查看指定数据库各表容量大小

select

table_schema as '数据库',

table_name as '表名',

table_rows as '记录数',

truncate(data_length/1024/1024, 2) as '数据容量(MB)',

truncate(index_length/1024/1024, 2) as '索引容量(MB)'

from information_schema.tables

where table_schema='your_table_name'

order by data_length desc, index_length desc;

8、将一个表的数据插入另外一个表

INSERT INTO 目标表 SELECT * FROM 来源表;

9、查询某字段出现的次数,用于处理重复的值

SELECT id ,COUNT(id) as count FROM huak_demo GROUP BY id;  其中id为要查的字段



10、MSSQL中按数据表内数据条数查询

SELECT  a.name 数据表,

        b.rows 数据总条数

FROM    sysobjects AS a

        INNER JOIN sysindexes AS b ON a.id = b.id

WHERE   ( a.type = 'u' )

        AND ( b.indid IN ( 0, 1 ) )

ORDER BY b.rows DESC;

mssql中筛选字段不为空的搞法SELECT * FROM [dbo].[ZL_Orderinfo] WHERE cast(Internalrecords as varchar(max))!='';


11查重复记录

SELECT COUNT(gid), gid FROM fsw_goods_price WHERE areaid=420000 GROUP BY gid HAVING COUNT(gid)>1;