我正在一个项目中,其中有两行具有完全相同的值,但只有一列。仅当存在两个条目时,我应该如何过滤掉其中的一行?
示例1图表:
R_Num R_Name Results
1001 NAME_1 PASSED
1002 NAME_2 PASSED
1002 NAME_2 FAILED
1003 NAME_3 FAILED
1004 NAME_4 PASSED
1004 NAME 4 FAILED
1005
结果图表:
R_Num R_Name Results
1001 NAME_1 PASSED
1002 NAME_2 PASSED
1003 NAME_3 FAILED
1004 NAME_4 PASSED
我希望能够消除给定R既有通过又有失败的行,而仅保留通过行。
EXAMPLE 2:
R_Num R_Name Results
1 Apple PASSED
2 Banana FAILED
3 Coconut PASSED
3 Coconut FAILED
4 Dates PASSED
5 Elderberry FAILED
6 Fig PASSED
6 Fig FAILED
RESULTS AFTER QUERY:
R_Num R_Name Results
1 Apple PASSED
2 Banana FAILED
3 Coconut PASSED
4 Dates PASSED
5 Elderberry FAILED
6 Fig PASSED
我需要将FAILED值保留在没有通过的相同R处。
答案 0 :(得分:2)
只需使用max()
select R_Num, R_Name, max(Results) as Results
from tab
group by R_Num, R_Name
答案 1 :(得分:0)
您可以使用聚合:
select r_num, r_name, max(results)
from t
group by r_num, r_name;
'pass'
> 'fail'
按字母顺序,因此如果两个都存在,则将返回它。