문제

I want to find the difference between two strings in MySQL. Say, if two strings like nishant and nisha are input, then 'nt' should be output.

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top