i have a customer table.
trans_id trans_date trans_amt debit_credit_indicator
001 01-JAN-13 1099 cr
001 12-JAN-13 500 db
002 24-FEB-13 400 db
002 23-MAR-13 345 cr
001 18-APR-13 800 cr
002 15-MAR-13 600 db
001 12-FEB-13 200 cr

i want like this output.

trans_id trans_amt debit_credit_indicator

i want get highest credit amount and lowest credit amount
and highest debit amount and lowest debit amount for each
trans_id.

Answer Posted / ajit

select ac_no, max(AC_STATUS) high,min(AC_STATUS) low,ac_branch
from DIM_ACCOUNt
where ac_branch = 'cr'
and ac_no = 1
group by ac_no, ac_branch
union
select ac_no, max(AC_STATUS) high,min(AC_STATUS) low,ac_branch
from DIM_ACCOUNt
where ac_branch = 'cr'
and ac_no = 2
group by ac_no, ac_branch
union
select ac_no, max(AC_STATUS) high,min(AC_STATUS) low,ac_branch
from DIM_ACCOUNt
where ac_branch = 'db'
and ac_no = 2
group by ac_no, ac_branch
union
select ac_no, max(AC_STATUS) high,min(AC_STATUS) low,ac_branch
from DIM_ACCOUNt
where ac_branch = 'db'
and ac_no = 1
group by ac_no, ac_branch;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a sql query to find the names of employees that begin with ‘a’?

576


What is time based sql injection?

486


Is left join inner or outer by default?

521


Does db2 use sql?

508


what is a constraint? Tell me about its various levels. : Sql dba

561






what is user defined functions? : Sql dba

545


How do you pronounce sql?

545


What is tuple in sql?

541


how can we destroy the cookie? : Sql dba

555


What are the indexing methods?

571


Which is better cte or subquery?

540


Suppose a student column has two columns, name and marks. How to get name and marks of the top three students.

525


How to combine two stored procedures in sql?

591


The select into statement is most often used to create backup copies of tables or for archiving records?

559


What is $$ in sql?

551