[英]How to select length of characters and column value?
I have this db http://sqlfiddle.com/#!18/24f134/4/0 of which extracts the longest word with points that contained within the word with no points. 我有这个数据库http://sqlfiddle.com/#!18/24f134/4/0 ,其中提取包含在单词中没有分数的点的最长单词。 I need to have the column (4th) of the word without points matching per row (that contains the word)
我需要有单词列(第4个),每行没有点匹配(包含单词)
If I understand correctly, you want the matching phrase (without points) for each row that has points. 如果我理解正确,你需要每个有点的行的匹配短语(没有点)。
APPLY
is useful in this situation: APPLY
在这种情况下很有用:
SELECT w.id, w.phrase, w.points, w2.phrase
FROM words w OUTER APPLY
(SELECT TOP (1) w2.*
FROM words w2
WHERE w2.phrase LIKE concat('%', w.phrase, '%') and w2.points = 0
ORDER BY len(w2.phrase) DESC
) w2
WHERE w.points > 0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.