-6
incident_number   Has_Breached   Id
INC15229006       Breached       1
INC15229006       Not Breached   2
INC15229006       Not Breached   3
INC15087939       Not Breached   4
INC15087939       Not Breached   5
INC15087939       Not Breached   6
INC15087939       Not Breached   7
INC15087939       Breached       8
INC15087939       Not Breached   9
INC15087939       Breached       10
INC15087940       Not Breached   13
INC15087940       Not Breached   12
INC15087940       Not Breached   24
INC15087940       Not Breached   32
INC15087940       Not Breached   45
INC15087940       Not Breached   67

我需要如下结果

incident_number   Has_Breached
INC15229006       Breached
INC15087939       Breached
INC15087940       Not Breached
4

1 回答 1

1

如果可能的值只有'Breachend''Not Breached',则可以GROUP BY incident_number和 得到最小值'Breached' < 'Not Breached'

SELECT incident_number,
       min(has_breached) has_breached
       FROM elbat
       GROUP BY incident_number;
于 2018-09-06T23:36:53.730 回答