如何比较同一列的两行

时间:2019-09-20 11:53:34

标签: sql oracle plsql

我有如下数据。我需要根据PART_KEY_ID比较ATTRIBUTE1_TXT。如果两个日期相同,我需要那个PART_KEY_ID。

PART_KEY_ID ATTRIBUTE1_TXT
504277          JUL 2019 (201)
504277          JUL 2019 (201)
5493605         JUL 2019 (201)
5493605         JUN 2018 (191)
4585233         JUL 2019 (201)
4585233         JUL 2019 (201)
6192893         JUL 2019 (201)
6192893         JUN 2018 (191)

所以输出应该是。

PART_KEY_ID
504277
4585233

5 个答案:

答案 0 :(得分:3)

var putRequest1 = new PutObjectRequest { BucketName = bucketName, Key = 
"Employee/Word.pdf", FilePath = filePath, }; PutObjectResponse response1 = 
await client.PutObjectAsync(putRequest1); var putRequest2 = new 
PutObjectRequest { BucketName = bucketName, Key = "Employee/Tenses.txt", 
FilePath = filePath, }; PutObjectResponse response2 = await 
client.PutObjectAsync(putRequest2); 

答案 1 :(得分:2)

这应该做您想要的:

ManualResetEvent

答案 2 :(得分:0)

这应该有效

select PART_KEY_ID from(select ATTRIBUTE1_TXT ,max(PART_KEY_ID),count(*) from table  group by ATTRIBUTE1_TXT having count(*) >1)t;

答案 3 :(得分:0)

   --this will work 
  --if you got three similar  ATTRIBUTE1_TXT for one PART_KEY_ID you can replace 
  ----having count(*)=2 in cte to having count(*)=3

   ;with cte as (
    select count(*) c,PART_KEY_ID,ATTRIBUTE1_TXT
    from table
    group by PART_KEY_ID,ATTRIBUTE1_TXT
    having count(*)=2
    ) 

    select PART_KEY_ID
    from cte

答案 4 :(得分:-1)

尝试此查询,我认为它应该可以满足您的需求。

SELECT PART_KEY_ID
FROM table_name
GROUP BY PART_KEY_ID, ATTRIBUTE1_TXT
HAVING COUNT(*) > 1