Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interactive input 1

Status
Not open for further replies.

marathon42

Programmer
Oct 21, 2002
2
0
0
DE
I need some help to solve the follwing problem:
I have to sort out hospital inpatients who have been in more than once in a given period, listing those periods.
Here is the syntax that works, BUT how can I solve the problem of having to input the dates (date1 & date2) twice??

select .....
from PATIENT A, OBJEKTE B
Where a.clinik_id = b.obj_id
and a.pid in (SELECT c.pid
FROM Patient c
WHERE c.pid IN
(SELECT pid
FROM patient
where admis_date
between :=date1 and :=date2
and exit_date is not null
GROUP pid HAVING COUNT(pid) > 1)
group by c.pid having count(*) > 1)

and admis_date between :=date1 and :=date2
and exit_date is not null
group by a.p_nr, b.obj_name, a.p_name, a.p_vorname,
a.admis_date, a.exit_date, a.ENTL_DIAGNOSE, a.pid
order by a.pid;
 
If you're running a current version of Oracle/DB2/Teradata the new SQL:1999 OLAP-functions may help:

select ...
from
(
select .....
,count(*) over (partition by a.pid rows between unbounded preceding and unbounded following) as cnt
from PATIENT A, OBJEKTE B
Where a.clinik_id = b.obj_id
and admis_date between :=date1 and :=date2
and exit_date is not null
) dt
where cnt > 1
group by a.p_nr, b.obj_name, a.p_name, a.p_vorname,
a.admis_date, a.exit_date, a.ENTL_DIAGNOSE, a.pid
order by a.pid;


Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top