Home » SQL & PL/SQL » SQL & PL/SQL » SQL problem
SQL problem [message #18839] Mon, 18 February 2002 06:25 Go to next message
Dave Adams
Messages: 1
Registered: February 2002
Junior Member
Hi,

I wonder if you can help? I need to find a way to extract some information from a table:

DATE COUNT BILL TAX REF_FROM REF_TO

2/2/02 50 5237.40 247.02 101974033 101974082
2/2/02 55 5651.45 266.74 101974033 101974087
2/2/02 46 4351.23 102.12 101974992 101975102

The problem is the column REF_FROM can contain a unique value or there can be a number of duplicates.
If REF_FROM is unique I want the whole line, however if REF_FROM is not unique I only want the line where REF_TO is the largest number. Is this possible to do with an SQL script?

Thanks in advance,
Dave.
Re: SQL problem [message #18840 is a reply to message #18839] Mon, 18 February 2002 07:34 Go to previous message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
select * from dave
where
(ref_to >ref_from
and 0=(select count(*) from (select count(*) a,count(distinct ref_from) b from dave)
where a=b)
)
or 0!=(select count(*) from (select count(*) a,count(distinct ref_from) b from dave)
where a=b)
Previous Topic: Function returning table parameter
Next Topic: Setting up and connecting HELP
Goto Forum:
  


Current Time: Thu Apr 18 20:20:23 CDT 2024