**Sample data**

```
+-------------------+-------------+-----------------+---------------------+
| RECORD_ID         | CUST_NO     | IsAccntClosed   | Code                |
+-------------------+-------------+-----------------+---------------------+
|159045             |   2439123   | N               |   13                |
+-------------------+-------------+-----------------+---------------------+
|159048             |   6376150   | Y               |   13                |
+-------------------+-------------+-----------------+---------------------+
|159048             |   9513035   | N               |   13                |
+-------------------+-------------+-----------------+---------------------+
|159049             |   2398524   | N               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159049             |   6349269   | Y               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159049             |   6350690   | Y               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159049             |   6372163   | Y               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159049             |   6393810   | Y               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159049             |   6402062   | Y               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159050             |   2677512   | Y               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159050             |   6349382   | Y               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159050             |   6378137   | Y               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159051             |   2336197   | N               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159051             |   6349293   | N               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159051             |   6350682   | N               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159051             |   6367895   | N               |   12                |
+-------------------+-------------+-----------------+---------------------+
|159060             |   yyyyyy    | Y               |   12                |
+-------------------+-------------+-----------------+---------------------+

```

IsAccntClosed column indicates if the account is Open (Y) or account is closed (Y). 

I need to select Record\_ID and cust\_no for only those rows for which which Record\_Id satisfies one of the below condition :  

1. Only one cust account is open , there might be one or multiple closed customers  

2. No open customer and only one closed customer 

Expected output :  

159045 2439123  

159048 9513035  

159049 2398524  

159060 yyyyyy 

A query like this would take each row as a single group and the count will come as 1 

```
select RECORD_ID, CUST_NO, IsAccntClosed, count(IsAccntClosed), Code
  from table1
 group by RECORD_ID, CUST_NO, IsAccntClosed, Code

```

Any suggestions on how this query could be written to get the expected output?