返回字符串的长度以进行比较

时间:2023-01-25 22:59:28

Is it possible to compare two strings on the length of the second string for example.

例如,是否可以比较第二个字符串长度上的两个字符串。

SELECT ProductDescription, Products  
FROM ProductDescription
INNER JOIN Products 
ON ProductDescription LIKE LEFT(Products, LENGTH(Products)) + '%'

Where Products is the string we are comparing with and the length of the comparison I would like to be the same length as the string if that makes sense?

如果Products是我们要比较的字符串和比较的长度,我希望与字符串的长度相同,如果这有意义的话?

Say we have Hydrogen and Hydrogen Oxide Like matches both so I need to specify what I am comparing...

假设我们有氢和氢氧化物匹配两者所以我需要指定我比较的...

further more the Description fields may for instance state:

更多描述字段可以例如说明:

Hydrogen Oxide is water. Oxygen is air. Hydrogen II and Oxygen II can be combined to create water. Hydrogen is a gas. Oxygen II is undefined.

氢氧化物是水。氧气是空气。可以将氢II和氧II组合以产生水。氢气是一种气体。氧气II未定义。

I have a list of states for example: Oxygen. Hydrogen. Oxygen II. Hydrogen II. Hydrogen Oxide.

我有一个状态列表,例如:氧气。氢。氧气II。氢II。氢氧化物。

I would like to append the Correct chemicals to the Descriptions they concern. for example:

我想将正确的化学品附加到他们关注的描述中。例如:

Hydrogen Oxide is water. | Hydrogen Oxide. Oxygen is air. | Oxygen Hydrogen II and Oxygen II can be combined to create water. | Hydrogen II, Oxygen II Hydrogen is a gas. | Hydrogen Oxygen II is undefined. | Oxygen II.

氢氧化物是水。 |氢氧化物。氧气是空气。 |可以将氧氢II和氧II组合以产生水。 |氢II,氧II氢是一种气体。 |氢氧II未定义。 |氧气II。

The results I can get from the query vary but I am trying to avoid:

我可以从查询得到的结果各不相同,但我试图避免:

Hydrogen Oxide is water. | Hydrogen Oxide. Oxygen is air. | Oxygen. Hydrogen II and Oxygen II can be combined to create water. | Oxygen II. Hydrogen II and Oxygen II can be combined to create water. | Hydrogen. II Hydrogen is a gas. | Hydrogen Oxygen II is undefined. | Oxygen.

氢氧化物是水。 |氢氧化物。氧气是空气。 |氧。可以将氢II和氧II组合以产生水。 |氧气II。可以将氢II和氧II组合以产生水。 |氢。 II氢是一种气体。 |氢氧II未定义。 |氧。

1 个解决方案

#1


1  

Hmmm. I am thinking you want:

嗯。我在想你想要:

SELECT ProductDescription, Products  
FROM ProductDescription INNER JOIN
     Products 
    ON ProductDescription LIKE Products + '%' OR
       Products LIKE ProductDescription + '%';

This is one way of accomplishing this. Note that the use of LIKE with wildcards will pretty much kill the performance of the query.

这是实现这一目标的一种方式。请注意,使用带有通配符的LIKE几乎会破坏查询的性能。

#1


1  

Hmmm. I am thinking you want:

嗯。我在想你想要:

SELECT ProductDescription, Products  
FROM ProductDescription INNER JOIN
     Products 
    ON ProductDescription LIKE Products + '%' OR
       Products LIKE ProductDescription + '%';

This is one way of accomplishing this. Note that the use of LIKE with wildcards will pretty much kill the performance of the query.

这是实现这一目标的一种方式。请注意,使用带有通配符的LIKE几乎会破坏查询的性能。