从不同字段中包含重复值的记录中查找唯一值

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

我试图返回过去 8 天内收到的 the_id 的所有值,并且至少有 1 个重复的名称。这应该返回 1,5。

MYTABLE

SELECT the_id, count(*) c 
FROM "MYTABLE" 
WHERE "received" < date('now','-8 days') 
GROUP BY the_name HAVING c > 1;
sql sqlite
1个回答
1
投票

这可能对你有用:

SELECT a.the_id
FROM   "MYTABLE" A, "MYTABLE" B
WHERE  (a.the_name = b.the_name)
       AND 
       (a."received" < date('now','-8 days') 
        AND b."received" < date('now','-8 days')
       )
Group by a.the_id 
having count(*)>1   
© www.soinside.com 2019 - 2024. All rights reserved.