简体   繁体   中英

How to check if a row of the first column is similar to the second?

I use the query

Select t1.name as first, t2.name as second From products t1, products t2

that creates two columns like below. (A,B are for explaining purposes)

Before the query

-name-
A
B
C
D
E

After the query

-first- -second-
A        A
B        A
C        A
D        A
E        A
A        B
B        B
C        B
D        B
E        B

How to check if a row of the first column is similar to the second ?

UPDATE

I run mySQL

With similar, I mean like to find their similarity percentage are more of a specified value. Like if the first contains this is a string and second i wear a string there is a percentage of similarity. If this % is more than 70 then they are similar.

there are many ways, here is one that will give you all the products that match your criteria (first = second)

SELECT
  t1.name AS first, t2.name AS second 
FROM
  products t1, products t2
WHERE
  t1.name = t2.name

or, if you need all the values

Select
  t1.name as first t2.name as second, (if t1.name = t2.name THEN 1 ELSE 0) as match
From 
  products t1, products t2

OK, here's what to do.

  1. run the select script like you do to get all possible combinations you want to calculate.
  2. make a php script that loops through each of these and calculates the percentage of similarity by using similar_text function in php (http://www.php.net/manual/en/function.similar-text.php)
  3. write all three values to a new table
  4. now just query the new table getting all rows where the percent is greater than 70.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM