select
	cntrycode,
	count(*) as numcust,
	sum(c_acctbal) as totacctbal
from
	(
		select
			c_phone as cntrycode,
			c_acctbal
		from
			customer
		where
			c_phone in
				(':1', ':2', ':3', ':4', ':5', ':6', ':7')
			and c_acctbal > (
				select
					avg(c_acctbal)
				from
					customer
				where
					c_acctbal > 0.00
					and c_phone  in
						(':1', ':2', ':3', ':4', ':5', ':6', ':7')
			)
			and not exists (
				select
					*
				from
					orders
				where
					o_custkey = c_custkey
			)
	) custsale
group by
	cntrycode
order by
	cntrycode
/

-- Q22 Plan Start --
Operation: table access
Options: FULL
Object_type: TABLE
Other: 
Object_owner: CALUSER01
Search_columns: 
Projection: C_ACCTBAL
Object_name: CUSTOMER
Alias: CUSTOMER@SEL$3
Extended_information:    FP:C_ACCTBAL>0.00 AND (C_PHONE=':1' OR C_PHONE=':2' OR C_PHONE=':3' OR C_PHONE=':4' OR C_PHONE=':5' OR C_PHONE=':6' OR C_PHONE=':7')
Access_predicates: 
Filter_predicates: C_ACCTBAL>0.00&(C_PHONE=':1'|C_PHONE=':2'|C_PHONE=':3'|C_PHONE=':4'|C_PHONE=':5'|C_PHONE=':6'|C_PHONE=':7')
Select_level: SEL$3
--------------------
Operation: sort
Options: AGGREGATE
Object_type: 
Other: 
Object_owner: 
Search_columns: 
Projection:  AVG(C_ACCTBAL)
Object_name: 
Alias: 
Extended_information: 
Access_predicates: 
Filter_predicates: 
Select_level: SEL$3
--------------------
Operation: table access
Options: FULL
Object_type: TABLE
Other: 
Object_owner: CALUSER01
Search_columns: 
Projection: C_CUSTKEY, C_PHONE, C_ACCTBAL
Object_name: CUSTOMER
Alias: CUSTOMER@SEL$2
Extended_information:    FP:(C_PHONE=':1' OR C_PHONE=':2' OR C_PHONE=':3' OR C_PHONE=':4' OR C_PHONE=':5' OR C_PHONE=':6' OR C_PHONE=':7') AND C_ACCTBAL> (SELECT AVG(C_ACCTBAL) FROM CUSTOMER CUSTOMER WHERE C_ACCTBAL>0.00 AND (C_PHONE=':1' OR C_PHONE=':2' OR C_PHONE=':3' OR C_PHONE=':4' OR C_PHONE=':5' OR C_PHONE=':6' OR C_PHONE=':7'))
Access_predicates: 
Filter_predicates: (C_PHONE=':1'|C_PHONE=':2'|C_PHONE=':3'|C_PHONE=':4'|C_PHONE=':5'|C_PHONE=':6'|C_PHONE=':7')&C_ACCTBAL> (SELECT AVG(C_ACCTBAL) FROM CUSTOMER CUSTOMER WHERE C_ACCTBAL>0.00&(C_PHONE=':1'|C_PHONE=':2'|C_PHONE=':3'|C_PHONE=':4'|C_PHONE=':5'|C_PHONE=':6'|C_PHONE=':7'))
Select_level: SEL$6B5772FB
--------------------
Operation: table access
Options: FULL
Object_type: TABLE
Other: 
Object_owner: CALUSER01
Search_columns: 
Projection: O_CUSTKEY
Object_name: ORDERS
Alias: ORDERS@SEL$4
Extended_information: 
Access_predicates: 
Filter_predicates: 
Select_level: SEL$6B5772FB
--------------------
Operation: hash join
Options: ANTI
Object_type: 
Other: 
Object_owner: 
Search_columns: 
Projection:  C_ACCTBAL, C_PHONE
Object_name: 
Alias: 
Extended_information:    AP:O_CUSTKEY=C_CUSTKEY
Access_predicates: O_CUSTKEY=C_CUSTKEY
Filter_predicates: 
Select_level: 
--------------------
Operation: sort
Options: GROUP BY
Object_type: 
Other: 
Object_owner: 
Search_columns: 
Projection:  C_PHONE, COUNT(ALL), SUM(C_ACCTBAL)
Object_name: 
Alias: 
Extended_information: 
Access_predicates: 
Filter_predicates: 
Select_level: SEL$6B5772FB
--------------------
Operation: select statement
Options: 
Object_type: 
Other: 
Object_owner: 
Search_columns: 
Projection: 
Object_name: 
Alias: 
Extended_information: 
Access_predicates: 
Filter_predicates: 
Select_level: 

-- End --
