【Mysql】 正则表达式
查看owner栏位中每一个值的出现次数。 sql
select distinct owner as uowner , count(*) as count 测试
from t_l0group by uowner spa
order by count DESC 字符串
【Mysql】模式匹配 REGEXP string
SELECT * FROM `t_l1` WHERE `file` REGEXP "custom/[_0-9a-zA-Z]+/modem/" it
【Mysql】substring()截取字符串 和 concat()链接字符串 扩展
SELECT file as afile,owner,context FROM `t_l0_mp1` WHERE context=(select context from t_l0_flag2 where file = substring(afile,19)) date
【Mysql】Left join ,right join,join(=inner join) file
A 右链接B,结果显示A的所有,反之,A左链接B,结果会显示B的所有
Select A.file,B.file
From t_l0_mp1 AS A
Left Join t_l0_flag2 AS B
On substring(A.file,20)=B.file and A.owner=B.owner and A.context=B.context
Select A.file,B.file
From t_l0_mp1 AS A
Join t_l0_flag2 AS B
On substring(A.file,20)=B.file and A.owner=B.owner and A.context=B.context
等同于
Select A.file,B.file
From t_l0_mp1 AS A,t_l0_flag2 AS B
WHERE substring(A.file,20)=B.file and A.owner=B.owner and A.context=B.context
【Mysql】联表更新 update + join
update t_l0_mp8 as A Join t_l0_flag2 as B
ON substring(A.file,20)=B.file
and A.owner = B.owner
and A.context = B.context
SET A.flag=2
【Mysql】取一个表数据插入另外一个表
INSERT IGNORE INTO `t_flag2`( `file`, `owner`, `context`) SELECT concat(substring_index(concat('/alps',substring_index(file,'/alps',-1)),'#',1),'#'),owner,context from t_l0_mp8 where flag=2
避免重复插入的方法 :ignore,Replace,ON DUPLICATE KEY UPDATE
【Mysql】
DELETE FROM sync_flag2 WHERE EXISTS (SELECT id from t_l0_mp2 AS B where (B.flag=4 or B.flag=1) and concat(substring_index(concat('/alps',substring_index(B.file,'/alps',-1)),'#',1),'#')=file and B.owner=owner and B.context=context)
DELETE FROM sync_flag2 AS A WHERE EXISTS (SELECT id from t_l0_mp2 AS B where (B.flag=4 or B.flag=1) and concat(substring_index(concat('/alps',substring_index(B.file,'/alps',-1)),'#',1),'#')=A.file and B.owner=A.owner and B.context=A.context)【DELETE FROM sync_flag2 AS A格式不能用在delete当中】
【Mysql】
使用“_”匹配任何单个字符,而“%”匹配任意数目字符(包括零个字符)。在 MySQL中,SQL的模式缺省是忽略大小写的。注意在你使用SQL模式时,你不能使用=或!=;而使用LIKE或NOT LIKE比较操做符。
由MySQL提供的模式匹配的其余类型是使用扩展正则表达式。当你对这类模式进行匹配测试时,使用REGEXP和NOT REGEXP操做符(或RLIKE和NOT RLIKE,它们是同义词)。
“.”匹配任何单个的字符。
一个字符类“[...]”匹配在方括号内的任何字符。例如,“[abc]”匹配“a”、“b”或“c”。为了命名字符的一个范围,使用一个“-”。
“[a-z]”匹配任何小写字母,而“[0-9]”匹配任何数字。
“ * ”匹配零个或多个在它前面的东西。例如,“x*”匹配任何数量的“x”字符,“[0-9]*”匹配的任何数量的数字,而“.*”匹配任何数量的任何东西。
正则表达式是区分大小写的,可是若是你但愿,你能使用一个字符类匹配两种写法。例如,“[aA]”匹配小写或大写的“a”而“[a-zA-Z]”匹配两种写法的任何字母。
若是它出如今被测试值的任何地方,模式就匹配(只要他们匹配整个值,SQL模式匹配)。
为了定位一个模式以便它必须匹配被测试值的开始或结尾,在模式开始处使用“^”或在模式的结尾用“$”。
为了说明扩展正则表达式如何工做,上面所示的LIKE查询在下面使用REGEXP重写:
为了找出以“b”开头的名字,使用“^”匹配名字的开始而且“[bB]”匹配小写或大写的“b”:
为了找出以“fy”结尾的名字,使用“$”匹配名字的结尾:
【Oracle】
round(to_number(sysdate-8/24-T1.submit_date))>=7
sysdate 比北京时间早8小时