SQL 包含返回不同结果的查询

问题描述 投票:0回答:1

我有一个简单的疑问

SELECT *
FROM QTests
WHERE CONTAINS(QTestId, '18 ~ 14 ~ 10')

每次运行它都会返回更多结果。

sql sql-server contains
1个回答
0
投票

SQL 语句旨在查询名为

QTests
的表,以查找
QTestId
列与
CONTAINS
关键字定义的特定搜索条件匹配的记录。以下是 SQL 代码块中的逐步解释:

-- Select all columns from the table
SELECT * 
FROM QTests -- Specifies the table to query, which is 'QTests' in this case
WHERE 
  CONTAINS(QTestId, '18 ~ 14 ~ 10') 
  -- The WHERE clause filters the rows returned by the SELECT statement.
  -- CONTAINS is a predicate used in the WHERE clause to search for a specific 
  -- pattern in the columns of Full-Text Indexed tables.
  -- QTestId is the column being searched.
  -- '18 ~ 14 ~ 10' is the search condition. In this context, the tilde (~) 
  -- operator is used in full-text search queries in SQL Server to specify a 
  -- proximity search. However, the exact syntax and meaning can depend on the 
  -- configuration and version of SQL Server. Typically, you would expect a 
  -- proximity search to find records where the specified terms ('18', '14', '10') 
  -- are near each other within the specified column. But, the provided syntax 
  -- does not correctly follow the standard SQL Server full-text search syntax 
  -- for proximity searches, which usually involves the NEAR operator or specifying 
  -- distances between words.
  -- It's important to note that the exact behavior of this query might not 
  -- perform as expected due to the syntax '18 ~ 14 ~ 10'. For a typical proximity 
  -- search, you might need to revise the syntax to align with SQL Server's 
  -- full-text search capabilities.

重要提示: 语法

'18 ~ 14 ~ 10'
不符合邻近搜索或典型
CONTAINS
搜索条件的标准 SQL Server 语法。在 SQL Server 中,您可以使用
NEAR
运算符进行邻近搜索,指定术语在文本中彼此的接近程度。执行邻近搜索或在
CONTAINS
查询中包含多个术语的正确方法可能看起来有所不同,通常涉及
AND
运算符、
OR
运算符或用于邻近的
NEAR
运算符。始终确保参考您正在使用的版本的特定 SQL Server 文档,因为功能和语法可能会有所不同。

来源

© www.soinside.com 2019 - 2024. All rights reserved.