【问题标题】:difference between two strings mysql [closed]两个字符串mysql之间的区别[关闭]
【发布时间】:2014-02-21 10:29:41
【问题描述】:

我想找出 MySQL 中两个字符串之间的区别。比如说,如果输入了 nishant 和 nisha 两个字符串,那么应该输出 'nt'。

【问题讨论】:

  • 你有没有尝试过?此外,您需要更好地定义“差异”;如果 "foo" 和 "bar" 是输入,那你期望什么?
  • 你应该澄清一下:如果你有aaaabcbc怎么办?输出会是空的吗?如果你有ac 怎么办?等等等等(在你的问题中做,而不是在评论中)。重复算不算,订单算不算,你的字段是什么类型...

标签: mysql string difference


【解决方案1】:
set @string2 :="nishant";
Query OK, 0 rows affected (0.00 sec)

set @string1 := "nisha";
Query OK, 0 rows affected (0.00 sec)

select @string1, @string2;
+----------+----------+
| @string1 | @string2 |
+----------+----------+
| nisha    | nishant  |
+----------+----------+
1 row in set (0.00 sec)

select if(length(@string1)>length(@string2), replace(@string1, @string2,""), replace(@string2, @string1, "")) as "The Difference";
+----------------+
| The Difference |
+----------------+
| nt             |
+----------------+
1 row in set (0.00 sec)

【讨论】:

    猜你喜欢
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 2015-02-18
    • 1970-01-01
    相关资源
    最近更新 更多