如何在分组后使用多列进行查询。
下表:
ord_num | loc | void | pay_type
-----------------------
10 | a101 | Y | CR
10 | a101 | N | AB
10 | a101 | N | CH
11 | a102 | N | CR
11 | a102 | Y | CR
12 | a103 | Y | JK
13 | a104 | N | CR
13 | a104 | Y | JK
14 | a104 | Y | CR
我需要带有ord_num的行,其中,pay_type只包含'CR'。
我期待下面的查询结果:
ord_num | loc
------------------
11 | a102
14 | a104
答案 0 :(得分:2)
select ord_num, loc
from table
group by ord_num, loc
having max(pay_type) = min(pay_type) and max(pay_type) = 'CR'
答案 1 :(得分:0)
select distinct ord_ num, loc
from yourTable
where pay_type = 'CR'