[Solved] SQL or Subquery if possible without using functions


You should use group by and sum, but before that, you should create two subqueries according to n_txn_type_key and then compare:

select txn_type_4.n_event_key, txn_type_4.tran_amount from 
(
    select n_event_key, sum(n_transaction_amount) as tran_amount from TABLE_NAME where
    n_txn_type_key = 4 group by n_event_key
) txn_type_4
inner join 
(
    select n_event_key, sum(n_transaction_amount) as tran_amount from TABLE_NAME where
    n_txn_type_key = 6 group by n_event_key
) txn_type_6 on txn_type_4.n_event_key = txn_type_6.n_event_key
where txn_type_4.tran_amount > txn_type_4.tran_amount

This query is for n_txn_type_key(4) > n_txn_type_key(6). By changing the where clause, you can reach what you want.

solved SQL or Subquery if possible without using functions