Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较mysql中的最后10个字符?_Mysql_Sql_Compare_Character_Match - Fatal编程技术网

比较mysql中的最后10个字符?

比较mysql中的最后10个字符?,mysql,sql,compare,character,match,Mysql,Sql,Compare,Character,Match,我有两张表:联系人和消息 联系人有:个人、地址 消息有:地址,消息 地址可以有10个以上的字符 联系人中的地址可能包含13个字符:abc9995551212 消息中的地址可能有11个字符:e9995551212 如何比较两个地址的最后10个字符 如果它们匹配,则创建具有以下内容的视图: contacts.person、messages.address、messages.message可以使用RIGHT函数返回字符串的n个右(最后)字符。从那以后,只需加入: SELECT contacts.per

我有两张表:联系人和消息

联系人有:个人、地址

消息有:地址,消息

地址可以有10个以上的字符

联系人中的地址可能包含13个字符:abc9995551212

消息中的地址可能有11个字符:e9995551212

如何比较两个地址的最后10个字符

如果它们匹配,则创建具有以下内容的视图:


contacts.person、messages.address、messages.message

可以使用
RIGHT
函数返回字符串的n个右(最后)字符。从那以后,只需加入:

SELECT contacts.person, messages.address, messages.message
FROM   contacts
JOIN   messages ON RIGHT(messages.address, 10) = RIGHT(contacts.address, 10)

RIGHT
函数可用于返回字符串的n个右(最后)字符。从那以后,只需加入:

SELECT contacts.person, messages.address, messages.message
FROM   contacts
JOIN   messages ON RIGHT(messages.address, 10) = RIGHT(contacts.address, 10)