如何在 SQL 服务器 table 列中查找相同值的行
How to find rows of same value in SQL Server table column
我有这样的查询:
SELECT
*
FROM
sub_aminer_paper
WHERE
p_abstract LIKE (
SELECT
p_abstract
FROM
sub_aminer_paper
GROUP BY
p_abstract
HAVING
COUNT(pid) > 1
)
AND
pid IN (784502,787096,789536)
ORDER BY
pid
我想从中检索列 p_abstract
具有相同值的行,其中数据类型为 text
中的 p_abstract
列。执行此查询时,出现以下错误:
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
检查这是否是您所期望的。
SELECT *
FROM sub_aminer_paper
WHERE pid IN (784502,787096,789536)
and CAST(p_abstract AS varchar(max)) in (
SELECT CAST(p_abstract AS varchar(max))
FROM sub_aminer_paper
WHERE pid IN (784502,787096,789536)
Group BY CAST(p_abstract AS varchar(max))
having count(*) > 1)
ORDER by pid
您需要比较文本字段的校验和
WITH PAPERS AS(
SELECT
pid,
BINARY_CHECKSUM(p_abstract) as chksum
FROM
sub_aminer_paper
), DOUBLES AS (
SELECT
chksum
,qty = COUNT(*)
FROM
papers
GROUP BY
chksum
HAVING
COUNT(*) > 1
)
SELECT *
FROM
PAPERS P
JOIN DOUBLES D ON P.chksum = D.chksum
我有这样的查询:
SELECT
*
FROM
sub_aminer_paper
WHERE
p_abstract LIKE (
SELECT
p_abstract
FROM
sub_aminer_paper
GROUP BY
p_abstract
HAVING
COUNT(pid) > 1
)
AND
pid IN (784502,787096,789536)
ORDER BY
pid
我想从中检索列 p_abstract
具有相同值的行,其中数据类型为 text
中的 p_abstract
列。执行此查询时,出现以下错误:
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
检查这是否是您所期望的。
SELECT *
FROM sub_aminer_paper
WHERE pid IN (784502,787096,789536)
and CAST(p_abstract AS varchar(max)) in (
SELECT CAST(p_abstract AS varchar(max))
FROM sub_aminer_paper
WHERE pid IN (784502,787096,789536)
Group BY CAST(p_abstract AS varchar(max))
having count(*) > 1)
ORDER by pid
您需要比较文本字段的校验和
WITH PAPERS AS(
SELECT
pid,
BINARY_CHECKSUM(p_abstract) as chksum
FROM
sub_aminer_paper
), DOUBLES AS (
SELECT
chksum
,qty = COUNT(*)
FROM
papers
GROUP BY
chksum
HAVING
COUNT(*) > 1
)
SELECT *
FROM
PAPERS P
JOIN DOUBLES D ON P.chksum = D.chksum