Dominic Veit  wrote:
> 
> Hy all,
> 
> in a clinical information system I am trying to count for 
> DISTINCT patients 
> born in a specific period. The data is collected by 
> subselects from different 
> tables. The query is as follows:
> 
> select count( distinct patient_guid ) from t_visite V where 
> $V_value AND 
> patient_guid in ( select patient_guid from t_visite where 
> guid in ( select 
> visite_guid from t_demographie where gebdat < 
> '".$age[0]."1231' AND ( gebdat 
> > '".$age[1]."0101' OR gebdat = '".$age[1]."0101' ) ) AND 
> patient_guid = 
> V.patient_guid )
> 

gebdat < '".$age[0]."1231'   --> you do not want to know those people born on the last 
day of the year?

gebdat > '".$age[1]."0101' OR gebdat = '".$age[1]."0101      strange, why don't you use
gebdat >= '".$age[1]."0101' 
and for the one above gebdat <= '".$age[0]."1231'  ?

And V.datum > '20030101'  seems to have the same problem >=


Perhaps there is a reason to have t_visite twice in your select.
But will not 

select count( distinct patient_guid ) from t_visite V 
where 
 $V_value AND 
 guid in ( select  visite_guid from t_demographie 
             where gebdat <=  '".$age[0]."1231' AND gebdat  >= '".$age[1]."0101' ) 

do what is needed?

> $V_value is: V.datum < '20030601' AND V.datum > '20030101' (a 
> specific time 
> where the patients to be counted must have visited the hospital).
> 
> $age[0] is the lower date of the "age" that shall be requested.
> $age[1] is the upper date of the "age" that shall be requested.
> 
> $age[0] and $age[1] are being calculated by subtraction from 
> the actual year. 
> The input then is:
> 
> 0-90
> 0-19
> 20-29
> 30-39
> 40-49
> 50-59
> 60-90
> 
> 0-90 would then mean that $age[0] is: 2003-0 = 2003
> and $age[1] = 2003-19 = 1984
> 
> In another query I try to get the patients that have visited 
> the hospital in 
> the requested period (the first part of the given query).
> 
> These two queries are both equal in their result when the 
> input to the given 
> query (with the ages) runs with 0-90 as input. However, if I 
> split this query 
> up in chunks (0-19 , 20-29 , 30-39 , ... ) and sum up the 
> results of the 
> chunks, the overall number is always one too high ( 0-90 = 92 
> , sum of chunks 
> = 93 ).
> 

  Sorry, but this I do not understand:
0-90 = 91 different values or do you mean that only 92 people were found in that 
period?

Are you sure that with every visite exactly one person/gebdat is combined?

Try
SELECT COUNT(gebdat),  visite_guid from t_demographie 
group by  visite_guid
HAVING COUNT(gebdat) > 1


Elke 
SAP Labs Berlin


> I am using PERL and the PERL-DB-interface SAP::DBTech::sapdb
> 
> Does anyone know what's happening there or does anyone see a 
> mistake in my 
> procedure? Even the second possibility would be extremely 
> helpfull for me.
> 
> Regards and thanx in advance,
> 
> Dominic
> 
> -- 
> Dominic Veit (Software Developer)
> Medical Center, University of Freiburg
> Dept. of Rheumatology and Clin. Immunology
> Hugstetterstr. 55
> 79106 Freiburg (Germany)
> Tel.: 0761 270 37 84
> Pager: 0168 73 22 60 0
> E-mail: [EMAIL PROTECTED]
> 
> _______________________________________________
> sapdb.general mailing list
> [EMAIL PROTECTED]
> http://listserv.sap.com/mailman/listinfo/sapdb.general
> 
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general

Reply via email to