The solution to this is to enumerate the rows that are being output and to only include the account id on the first row in each group:
select (case when seqnum = 1 then Account_Id else '' end),
Transaction_type, cost
from (select b.ACCOUNT_ID, b.TRANSACTION_TYPE, b.cost,
row_number() over (partition by account_id
order by b.bill_transacction_id) as seqnum
from mdw_bill1 a, mdw_bill_transaction1 b
where a.CUSTOMER_Id='CUS0033'and a.month='JUN' and a.year=2013
) t
order by Account_id, seqnum
Some comments. You should give your tables sensible aliases, like b
for mdw_bill1
and bt
for mdw_bill_transaction
. Your original query did not have an order by
clause; you need that to guarantee the ordering of the rows -- no guarantee that one account will always be on adjacent lines. Third, joining two tables this way looks . . . shall I say awkward. I think you intend for the conditions to be:
from mdw_bill1 a join
mdw_bill_transaction1 b
on a.bill_id = b.bill_id
where a.CUSTOMER_Id='CUS0033'and a.month='JUN' and a.year=2013