Sybase Vs PostgreSQL
3 partecipanti
Pagina 1 di 2 • 1, 2
Sybase Vs PostgreSQL
Chiedo agli esperti se mi danno una mano a rendere questa query adattabile a PostgreSQL.
Grazie.
Select LIST(distinct n.Pa_medi) Codice_medico,
(Select COUNT(*) FROM pazienti p, NOS_002 n Where p.codice=n.codice AND p.decesso is null and p.Sesso = 'M' AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND n.Pa_medi like '%' ) Assisititi_M,
(Select COUNT(*) FROM pazienti p, NOS_002 n Where p.codice=n.codice AND p.decesso is null AND p.Sesso = 'F' AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND n.Pa_medi like '%' ) Assisititi_F,
(Select COUNT(distinct a.codice) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today())
AND a.ac_des like '%uricemia%' AND a.ac_val is not null AND p.Sesso = 'M' AND n.Pa_medi like '%') M_con_uricemia ,
(Select COUNT(distinct a.codice) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today())
AND a.ac_des like '%uricemia%' AND a.ac_val is not null AND p.Sesso = 'F' AND n.Pa_medi like '%') F_con_uricemia ,
' Uricemia > 7 => ' Iperuricemici,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) Between '0' AND '40' AND n.Pa_medi like '%') gruppo1_0_40_M ,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice and p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) Between '0' AND '40' AND n.Pa_medi like '%') gruppo1_0_40_F,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) Between '41' AND '64' AND n.Pa_medi like '%') gruppo2_41_65_M,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) Between '41' AND '64' AND n.Pa_medi like '%') gruppo2_41_65_F,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) >= '65' AND n.Pa_medi like '%') gruppo3_M65_M,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) >= '65' AND n.Pa_medi like '%') gruppo3_M65_F,
' Iperuricemia_cronica => ' Iperuricemia_cronica,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) Between '0' AND '40' AND n.Pa_medi like '%') gruppo4_0_40_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) Between '0' AND '40' AND n.Pa_medi like '%') gruppo4_0_40_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) Between '41' AND '64' AND n.Pa_medi like '%') gruppo5_41_65_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) Between '41' AND '64' AND n.Pa_medi like '%') gruppo5_41_65_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%'AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) >= '65' AND n.Pa_medi like '%') gruppo6_M_65_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) >= '65' AND n.Pa_medi like '%') gruppo6_M_65_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code BETWEEN '401%' AND '405%')) Iperuric_Ipertensione_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code BETWEEN '401%' AND '405%')) Iperuric_Ipertensione_F,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code LIKE '272%')) Iperuric_dislipidemia_M,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%'AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code LIKE '272%')) Iperuric_dislipidemia_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '250%' )) Iperuric_Diabete_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%'AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '250%' )) Iperuric_Diabete_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '436%' )) Iperurc_Ictus_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '436%' )) Iperurc_Ictus_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '290%' )) Iperuric_Demenza_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '290%' )) Iperuric_Demenza_F,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '414%' )) Iperuric_Cardiopatia_M,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '414%' )) Iperuric_Cardiopatia_F,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '428%' )) Iperuric_Scomp_Card_M,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '428%' )) Iperuric_Scomp_Card_F,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND n.Pa_medi like '%' AND exists (select t.codice FROM cart_terap t WHERE a.codice=t.codice AND t.co_atc like 'M04AA01' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' )) Allopurinolo_cont,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND n.Pa_medi like '%' AND exists (select t.codice FROM cart_terap t WHERE a.codice=t.codice AND t.co_atc like 'M04AA03' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' )) Febuxostat_cont,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select c.codice FROM cart_accert c WHERE a.codice=c.codice AND c.ac_des like '%uricemia%' AND c.ac_val <6 AND c.data_Open >Today()-365)) Uricemia_inf_6_M,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select c.codice FROM cart_accert c WHERE a.codice=c.codice AND c.ac_des like '%uricemia%' AND c.ac_val <6 AND c.data_Open >Today()-365)) Uricemia_inf_6_F
FROM nos_002 n
WHERE n.Pa_medi like '%'
Grazie.
Select LIST(distinct n.Pa_medi) Codice_medico,
(Select COUNT(*) FROM pazienti p, NOS_002 n Where p.codice=n.codice AND p.decesso is null and p.Sesso = 'M' AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND n.Pa_medi like '%' ) Assisititi_M,
(Select COUNT(*) FROM pazienti p, NOS_002 n Where p.codice=n.codice AND p.decesso is null AND p.Sesso = 'F' AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND n.Pa_medi like '%' ) Assisititi_F,
(Select COUNT(distinct a.codice) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today())
AND a.ac_des like '%uricemia%' AND a.ac_val is not null AND p.Sesso = 'M' AND n.Pa_medi like '%') M_con_uricemia ,
(Select COUNT(distinct a.codice) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today())
AND a.ac_des like '%uricemia%' AND a.ac_val is not null AND p.Sesso = 'F' AND n.Pa_medi like '%') F_con_uricemia ,
' Uricemia > 7 => ' Iperuricemici,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) Between '0' AND '40' AND n.Pa_medi like '%') gruppo1_0_40_M ,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice and p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) Between '0' AND '40' AND n.Pa_medi like '%') gruppo1_0_40_F,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) Between '41' AND '64' AND n.Pa_medi like '%') gruppo2_41_65_M,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) Between '41' AND '64' AND n.Pa_medi like '%') gruppo2_41_65_F,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) >= '65' AND n.Pa_medi like '%') gruppo3_M65_M,
(Select COUNT(*) FROM cart_accert a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.ac_des like '%uricemia%' AND a.ac_val >7 AND YEARS(p.nascita, Today()) >= '65' AND n.Pa_medi like '%') gruppo3_M65_F,
' Iperuricemia_cronica => ' Iperuricemia_cronica,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) Between '0' AND '40' AND n.Pa_medi like '%') gruppo4_0_40_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) Between '0' AND '40' AND n.Pa_medi like '%') gruppo4_0_40_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) Between '41' AND '64' AND n.Pa_medi like '%') gruppo5_41_65_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) Between '41' AND '64' AND n.Pa_medi like '%') gruppo5_41_65_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%'AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) >= '65' AND n.Pa_medi like '%') gruppo6_M_65_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND YEARS(p.nascita, Today()) >= '65' AND n.Pa_medi like '%') gruppo6_M_65_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code BETWEEN '401%' AND '405%')) Iperuric_Ipertensione_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code BETWEEN '401%' AND '405%')) Iperuric_Ipertensione_F,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code LIKE '272%')) Iperuric_dislipidemia_M,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%'AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code LIKE '272%')) Iperuric_dislipidemia_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '250%' )) Iperuric_Diabete_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%'AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '250%' )) Iperuric_Diabete_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '436%' )) Iperurc_Ictus_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '436%' )) Iperurc_Ictus_F,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '290%' )) Iperuric_Demenza_M,
(Select COUNT(*) FROM cart_pazpbl a , pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '290%' )) Iperuric_Demenza_F,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '414%' )) Iperuric_Cardiopatia_M,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '414%' )) Iperuric_Cardiopatia_F,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '428%' )) Iperuric_Scomp_Card_M,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select b.codice FROM cart_pazpbl b WHERE a.codice=b.codice AND b.Cp_Code like '428%' )) Iperuric_Scomp_Card_F,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND n.Pa_medi like '%' AND exists (select t.codice FROM cart_terap t WHERE a.codice=t.codice AND t.co_atc like 'M04AA01' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' )) Allopurinolo_cont,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND n.Pa_medi like '%' AND exists (select t.codice FROM cart_terap t WHERE a.codice=t.codice AND t.co_atc like 'M04AA03' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' )) Febuxostat_cont,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'M' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select c.codice FROM cart_accert c WHERE a.codice=c.codice AND c.ac_des like '%uricemia%' AND c.ac_val <6 AND c.data_Open >Today()-365)) Uricemia_inf_6_M,
(Select COUNT(*) FROM cart_pazpbl a, pazienti p, NOS_002 n WHERE a.codice=p.codice AND p.codice=n.codice AND p.Sesso = 'F' AND p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND a.Cp_Code like '274%' AND a.Cp_Cod2 <> '01' AND n.Pa_medi like '%' AND exists (select c.codice FROM cart_accert c WHERE a.codice=c.codice AND c.ac_des like '%uricemia%' AND c.ac_val <6 AND c.data_Open >Today()-365)) Uricemia_inf_6_F
FROM nos_002 n
WHERE n.Pa_medi like '%'
Re: Sybase Vs PostgreSQL
non ho Postgres, ma -FORSE ??? -da fastidio la prima riga:
Select LIST(distinct n.Pa_medi) Codice_medico
da sostituire con Select distinct n.Pa_medi Codice_medico
Comunque io sarei per faticare di meno e l'ho accorciata un pò (circa la metà) . I dati mi sembrano gli stessi.
SELECT codmedico, sesso as sex, count (*)assistiti,
(Select COUNT(distinct a.codice) FROM cart_accert a
where a.ac_des like '%uricemia%' AND a.ac_val is not null
and a.codice IN
(select codice from V_pazienti where sesso =sex)) as __con_uricemia__,
'iperuricemici',
(Select COUNT(distinct codice)
FROM cart_accert WHERE ac_des like '%uricemia%' AND ac_val >7
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) <=40 ))
g1_0_40,
(Select COUNT(distinct codice)
FROM cart_accert WHERE ac_des like '%uricemia%' AND ac_val >7
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) Between '41' AND '65' ))
g2_41_65,
(Select COUNT(distinct codice)
FROM cart_accert WHERE ac_des like '%uricemia%' AND ac_val >7
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) > 65 ))
g3_m65,
'iperuricemia_cronica',
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01'
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) Between '0' AND '40' ))g4_0_40,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01'
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) Between '41' AND '65' )) g5_41_65,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01'
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) > 65 ))
g6_m65,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code BETWEEN '401%' AND '405%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_Iperten,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '272%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_Dislip,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '250%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_Diab,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '436%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_ictus,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '290%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_demenza,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '414%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_cardiop,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '428%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_scomp_c,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '274%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select t.codice FROM cart_terap t where t.co_atc like 'M04AA01' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' )) allopurinolo_C,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '274%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select t.codice FROM cart_terap t WHERE t.co_atc like 'M04AA03' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' )) Febuxostat_C,
(Select COUNT(distinct codice)
FROM cart_accert WHERE ac_des like '%uricemia%' AND ac_val <6
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Uricemia_inf_6
from V_pazienti
group by codmedico, sesso
Select LIST(distinct n.Pa_medi) Codice_medico
da sostituire con Select distinct n.Pa_medi Codice_medico
Comunque io sarei per faticare di meno e l'ho accorciata un pò (circa la metà) . I dati mi sembrano gli stessi.
SELECT codmedico, sesso as sex, count (*)assistiti,
(Select COUNT(distinct a.codice) FROM cart_accert a
where a.ac_des like '%uricemia%' AND a.ac_val is not null
and a.codice IN
(select codice from V_pazienti where sesso =sex)) as __con_uricemia__,
'iperuricemici',
(Select COUNT(distinct codice)
FROM cart_accert WHERE ac_des like '%uricemia%' AND ac_val >7
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) <=40 ))
g1_0_40,
(Select COUNT(distinct codice)
FROM cart_accert WHERE ac_des like '%uricemia%' AND ac_val >7
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) Between '41' AND '65' ))
g2_41_65,
(Select COUNT(distinct codice)
FROM cart_accert WHERE ac_des like '%uricemia%' AND ac_val >7
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) > 65 ))
g3_m65,
'iperuricemia_cronica',
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01'
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) Between '0' AND '40' ))g4_0_40,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01'
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) Between '41' AND '65' )) g5_41_65,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01'
AND codice IN
(select codice from V_pazienti where sesso =sex and YEARS(datanasc, Today()) > 65 ))
g6_m65,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code BETWEEN '401%' AND '405%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_Iperten,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '272%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_Dislip,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '250%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_Diab,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '436%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_ictus,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '290%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_demenza,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '414%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_cardiop,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '428%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Iperuric_scomp_c,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '274%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select t.codice FROM cart_terap t where t.co_atc like 'M04AA01' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' )) allopurinolo_C,
(Select COUNT(distinct codice)
FROM cart_pazpbl WHERE Cp_Code LIKE '274%'
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select t.codice FROM cart_terap t WHERE t.co_atc like 'M04AA03' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' )) Febuxostat_C,
(Select COUNT(distinct codice)
FROM cart_accert WHERE ac_des like '%uricemia%' AND ac_val <6
AND codice IN
(select codice from V_pazienti where sesso =sex)
AND codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' AND Cp_Cod2 <> '01' ))
Uricemia_inf_6
from V_pazienti
group by codmedico, sesso
draleo83- Membro Junior
- Messaggi : 225
Punti : 5309
Voti per importanza dei messaggi : 25
Data d'iscrizione : 21.02.11
Re: Sybase Vs PostgreSQL
l'errore dice che non esiste la colonna sex. Ma nel mio Sybase funziona perfettamente ; quindi deduco che dipenda da postgres. Francamente non saprei come modificare, perché non ho post gres. Prova con la tua query, ma togli quel list dalla prima riga (forse è questo che non viene accettato da postgres). Ciao
Leonardo
Leonardo
draleo83- Membro Junior
- Messaggi : 225
Punti : 5309
Voti per importanza dei messaggi : 25
Data d'iscrizione : 21.02.11
Re: Sybase Vs PostgreSQL
Non funziona neanche sostituendo la prima riga.draleo83 ha scritto:l'errore dice che non esiste la colonna sex. Ma nel mio Sybase funziona perfettamente ; quindi deduco che dipenda da postgres. Francamente non saprei come modificare, perché non ho post gres. Prova con la tua query, ma togli quel list dalla prima riga (forse è questo che non viene accettato da postgres). Ciao
Leonardo
Grazie lo stesso.
Re: Sybase Vs PostgreSQL
Ciao Renato , prova con la query ( corrette alcune imprecisioni nei codici ICD9 , eliminate 2 subquery doppie ) :
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_M_ ,
/* ( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 > 64 And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */
And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_gruppo6_M_65_99_M_1_ , */
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )))
_Iperuric_Ipertensione_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )))
_Iperuric_Ipertensione_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ))
_Iperuric_DisLipidemia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ))
_Iperuric_DisLipidemia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ))
_Iperuric_Diabete_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ))
_Iperuric_Diabete_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ))
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ))
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ))
_Iperuric_Demenza_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ))
_Iperuric_Demenza_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ))
_Iperuric_Cardiopatia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ))
_Iperuric_Cardiopatia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ))
_Iperuric_Scomp_Card_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ))
_Iperuric_Scomp_Card_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
_Allopurinolo_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA03' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
_Febuxostat_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) < 7 )
_Uricemia_inf_7_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) < 6 )
_Uricemia_inf_6_F_
FROM nos_002 n WHERE n.pa_medi ILike '%'
Presenta minime differenze con la query analitica ( trascurabili sul mio MillePS monoutente ) :
Select Distinct p.cognome , p.nome , p.sesso , Days( p.nascita , Today())*24/8766 As eta ,
( Select Year( Max( b.data_open)) From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274%' And Not ( b.pb_status = 'I' And b.modalita ='A' ) )
_Iperuricemia_ ,
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 )
And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) )
_Ac_Ur_ ,
( Select Max( t.data_open) From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And ( t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' OR t.data_open > Today()-180 ) )
_Allopurinolo_ ,
( Select Max( t.data_open) From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA03' And ( t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' OR t.data_open > Today()-180 ) )
_Febuxostat_
FROM pazienti p LEFT Outer JOIN nos_002 n ON p.codice = n.codice
WHERE p.pa_convenzione = 'S' AND ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S'))
AND p.decesso Is Null AND Sesso ILike '%' AND ( Case WHEN p.sesso = 'M' THEN
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) > 7 ELSE ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) > 6 END
OR ( Select Year( Max( b.data_open)) From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274%' And Not ( b.pb_status = 'I' And b.modalita ='A' ) ) > 0 )
Order By 6 , 1 , 2
Verificare le varie clausole delle condizioni di ricerca : fornirà dati attendibili o solo numeri da giocare al Lotto ?
( con l' utilizzo estensivo della funzione Count , le sorprese sono sempre possibili )
Sorprendente la query suggerita da Leonardo ( che non ho ancora compreso : ma c' è sempre qualcosa da Imparare dai Maestri )
Un Saluto a Tutti gli Utenti del Forum Sergio , Orzivecchi BS
PS : la stessa query x un Mille.db Sybase ( funzionerà ? ) :
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And ( a.ac_code Like ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And ( a.ac_code Like ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_M_ ,
/* ( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And Days( p.nascita , Today())*24/8766 > 64 And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */
And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_gruppo6_M_65_99_M_1_ , */
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code Like '401%' Or b.cp_code Like '402%' Or b.cp_code Like '403%' Or b.cp_code Like '404%' Or b.cp_code Like '405%' )))
_Iperuric_Ipertensione_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code Like '401%' Or b.cp_code Like '402%' Or b.cp_code Like '403%' Or b.cp_code Like '404%' Or b.cp_code Like '405%' )))
_Iperuric_Ipertensione_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '272%' ))
_Iperuric_DisLipidemia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '272%' ))
_Iperuric_DisLipidemia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '250%' ))
_Iperuric_Diabete_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '250%' ))
_Iperuric_Diabete_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '436%' ))
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '436%' ))
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '290%' ))
_Iperuric_Demenza_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '290%' ))
_Iperuric_Demenza_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '414%' ))
_Iperuric_Cardiopatia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '414%' ))
_Iperuric_Cardiopatia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '428%' ))
_Iperuric_Scomp_Card_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '428%' ))
_Iperuric_Scomp_Card_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc Like 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
_Allopurinolo_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc Like 'M04AA03' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
_Febuxostat_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) < 7 )
_Uricemia_inf_7_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) < 6 )
_Uricemia_inf_6_F_
FROM nos_002 n WHERE n.pa_medi Like '%'
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_M_ ,
/* ( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 > 64 And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */
And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_gruppo6_M_65_99_M_1_ , */
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )))
_Iperuric_Ipertensione_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )))
_Iperuric_Ipertensione_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ))
_Iperuric_DisLipidemia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ))
_Iperuric_DisLipidemia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ))
_Iperuric_Diabete_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ))
_Iperuric_Diabete_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ))
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ))
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ))
_Iperuric_Demenza_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ))
_Iperuric_Demenza_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ))
_Iperuric_Cardiopatia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ))
_Iperuric_Cardiopatia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ))
_Iperuric_Scomp_Card_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ))
_Iperuric_Scomp_Card_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
_Allopurinolo_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA03' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
_Febuxostat_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) < 7 )
_Uricemia_inf_7_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) < 6 )
_Uricemia_inf_6_F_
FROM nos_002 n WHERE n.pa_medi ILike '%'
Presenta minime differenze con la query analitica ( trascurabili sul mio MillePS monoutente ) :
Select Distinct p.cognome , p.nome , p.sesso , Days( p.nascita , Today())*24/8766 As eta ,
( Select Year( Max( b.data_open)) From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274%' And Not ( b.pb_status = 'I' And b.modalita ='A' ) )
_Iperuricemia_ ,
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 )
And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) )
_Ac_Ur_ ,
( Select Max( t.data_open) From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And ( t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' OR t.data_open > Today()-180 ) )
_Allopurinolo_ ,
( Select Max( t.data_open) From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA03' And ( t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' OR t.data_open > Today()-180 ) )
_Febuxostat_
FROM pazienti p LEFT Outer JOIN nos_002 n ON p.codice = n.codice
WHERE p.pa_convenzione = 'S' AND ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S'))
AND p.decesso Is Null AND Sesso ILike '%' AND ( Case WHEN p.sesso = 'M' THEN
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) > 7 ELSE ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) > 6 END
OR ( Select Year( Max( b.data_open)) From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274%' And Not ( b.pb_status = 'I' And b.modalita ='A' ) ) > 0 )
Order By 6 , 1 , 2
Verificare le varie clausole delle condizioni di ricerca : fornirà dati attendibili o solo numeri da giocare al Lotto ?
( con l' utilizzo estensivo della funzione Count , le sorprese sono sempre possibili )
Sorprendente la query suggerita da Leonardo ( che non ho ancora compreso : ma c' è sempre qualcosa da Imparare dai Maestri )
Un Saluto a Tutti gli Utenti del Forum Sergio , Orzivecchi BS
PS : la stessa query x un Mille.db Sybase ( funzionerà ? ) :
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And ( a.ac_code Like ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And ( a.ac_code Like ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_M_ ,
/* ( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And Days( p.nascita , Today())*24/8766 > 64 And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */
And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_gruppo6_M_65_99_M_1_ , */
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code Like '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code Like '401%' Or b.cp_code Like '402%' Or b.cp_code Like '403%' Or b.cp_code Like '404%' Or b.cp_code Like '405%' )))
_Iperuric_Ipertensione_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code Like '401%' Or b.cp_code Like '402%' Or b.cp_code Like '403%' Or b.cp_code Like '404%' Or b.cp_code Like '405%' )))
_Iperuric_Ipertensione_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '272%' ))
_Iperuric_DisLipidemia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '272%' ))
_Iperuric_DisLipidemia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '250%' ))
_Iperuric_Diabete_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '250%' ))
_Iperuric_Diabete_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '436%' ))
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '436%' ))
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '290%' ))
_Iperuric_Demenza_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '290%' ))
_Iperuric_Demenza_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '414%' ))
_Iperuric_Cardiopatia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '414%' ))
_Iperuric_Cardiopatia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '428%' ))
_Iperuric_Scomp_Card_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso Like 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '428%' ))
_Iperuric_Scomp_Card_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc Like 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
_Allopurinolo_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code Like '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc Like 'M04AA03' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
_Febuxostat_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) < 7 )
_Uricemia_inf_7_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso Like 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select a.ac_val +0 From cart_accert a Where a.codice = p.codice And ( a.ac_code Like ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code Like ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) < 6 )
_Uricemia_inf_6_F_
FROM nos_002 n WHERE n.pa_medi Like '%'
Ultima modifica di Cervino il Dom 31 Mag 2015 - 0:42 - modificato 1 volta.
Cervino- Membro Junior
- Messaggi : 245
Punti : 5283
Voti per importanza dei messaggi : 22
Data d'iscrizione : 03.03.11
Età : 70
Località : Orzivecchi (BS)
Re: Sybase Vs PostgreSQL
Grazie Sergio,
ma mi dà il seguente errore: il campo numeric causa un overflow...Select LIST (distinct n.pa_medi) As mmg_co
Non riesco ad allegare l'immagine dell'errore per essere più preciso, ma fammi sapere se serve.
Un abbraccio
P.S.: tra te e Leo scontro di Titani
ma mi dà il seguente errore: il campo numeric causa un overflow...Select LIST (distinct n.pa_medi) As mmg_co
Non riesco ad allegare l'immagine dell'errore per essere più preciso, ma fammi sapere se serve.
Un abbraccio
P.S.: tra te e Leo scontro di Titani
Re: Sybase Vs PostgreSQL
Mah… i presunti maestri (dilettanti ) ormai attendono solo di arrivare alla pensione e raramente si interessano più all’ argomento (forse solo quando intravedono qualche possibile soluzione nuova ed originale da sperimentare ). Forse 25 anni fa …quando eravamo in pochissimi a cimentarsi rudimentalmente con l’SQL … qualcosa potevo anche dire (anche se rivedendo le mie query di allora quasi mi vergogno per le inesattezze ed errori compiuti)
Comunque la query che ho modificato (senza rifletterci troppo) non ha niente di particolare
1)ho utilizzato la vista V_pazienti per evitare il ripetersi in tutte le subquery del ritornello di p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND n.Pa_medi like '%'. così si evita a chi l’utilizzerà il fastidio di introdurre il proprio codice di Medicina di gruppo in tutte le subquery
2) ho notato che tutte –o quasi- le subquery erano doppie (una per i maschi , una per le femmine); quindi ho introdotto il campo Sesso e la clausola By sesso. In tal modo l’output finale restituisce 2 righe: una per i Maschi ,una per le femmine (e i dati possono essere più facilmente leggibili). ma soprattutto il num delle subquery si è dimezzato . Non ho fatto grandi controlli , ma sembra funzionare (purtroppo solo con Sybase e non con Postgres, perché quest’ultimo –credo- non vuole riferimenti ai nomi (alias) delle colonne (in questo caso sex). Sicuramente Sergio-se vuol divertirsi un po’- può trovare la soluzione. Io non ho idea di come si possa fare
Leonardo
Comunque la query che ho modificato (senza rifletterci troppo) non ha niente di particolare
1)ho utilizzato la vista V_pazienti per evitare il ripetersi in tutte le subquery del ritornello di p.decesso is null AND (n.Pa_drevoca is null OR n.Pa_drevoca >Today()) AND n.Pa_medi like '%'. così si evita a chi l’utilizzerà il fastidio di introdurre il proprio codice di Medicina di gruppo in tutte le subquery
2) ho notato che tutte –o quasi- le subquery erano doppie (una per i maschi , una per le femmine); quindi ho introdotto il campo Sesso e la clausola By sesso. In tal modo l’output finale restituisce 2 righe: una per i Maschi ,una per le femmine (e i dati possono essere più facilmente leggibili). ma soprattutto il num delle subquery si è dimezzato . Non ho fatto grandi controlli , ma sembra funzionare (purtroppo solo con Sybase e non con Postgres, perché quest’ultimo –credo- non vuole riferimenti ai nomi (alias) delle colonne (in questo caso sex). Sicuramente Sergio-se vuol divertirsi un po’- può trovare la soluzione. Io non ho idea di come si possa fare
Leonardo
draleo83- Membro Junior
- Messaggi : 225
Punti : 5309
Voti per importanza dei messaggi : 25
Data d'iscrizione : 21.02.11
Re: Sybase Vs PostgreSQL
Magari!!! Tutte le modifiche che ha apportato Leonardo, sebbene non le abbia potute constatare perché ho postgreSQL, mi sembrano molto utili anche solo per non dover scrivere molte volte il codice della medicina di gruppo.draleo83 ha scritto: Sicuramente Sergio-se vuol divertirsi un po’- può trovare la soluzione.
Re: Sybase Vs PostgreSQL
drtulino ha scritto:Grazie Sergio,
ma mi dà il seguente errore: il campo numeric causa un overflow...Select LIST (distinct n.pa_medi) As mmg_co
Non riesco ad allegare l'immagine dell'errore per essere più preciso, ma fammi sapere se serve.
Un abbraccio
Ciao Renato ma almeno la seconda query funziona ? ( sul mio MillePs MonoUtente ( purtroppo e datato : PS v9.0.3 - MW 13.38.156 ) , la I query viene eseguita molto velocemente anche in MilleUtilità ) . Quando una query complessa non funziona bisogna procedere passo passo , eseguendone solo una parte ( basta togliere subquery fino a trovare il blocco nella ricerca ; meglio forse inserire un codice n.pa_medi x velocizzare le prove ) :
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ , ' '
FROM nos_002 n WHERE n.pa_medi ILike '%'
se x caso dovesse funzionare , aggiungere subquery , altrimente toglierne 1 2 e ripetere l' estrazione :
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo4_0_40_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo5_41_64_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_M_ ,
/* ( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 > 64 And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))) _gruppo6_M_65_99_M_1_ , */
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ))
_gruppo6_M_65_99_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )))
_Iperuric_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today () Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )))
_Iperuric_Ipertensione_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today () Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )))
_Iperuric_Ipertensione_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today () Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ))
_Iperuric_DisLipidemia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today () Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ))
_Iperuric_DisLipidemia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ))
_Iperuric_Diabete_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ))
_Iperuric_Diabete_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ))
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ))
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ))
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ))
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ))
_Iperuric_Demenza_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ))
_Iperuric_Demenza_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ))
_Iperuric_Cardiopatia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ))
_Iperuric_Cardiopatia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ))
_Iperuric_Scomp_Card_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ))
_Iperuric_Scomp_Card_F_ , ' '
FROM nos_002 n WHERE n.pa_medi ILike '%'
se x caso dovesse funzionare , aggiungere subquery ( nell' esempio in blocchi omogenei ), altrimente toglierne 1 2 x prova :
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' '
FROM nos_002 n WHERE n.pa_medi ILike '%'
se x caso dovesse funzionare , aggiungere subquery , altrimente toglierne 1 2 e ripetere l' estrazione :
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' '
FROM nos_002 n WHERE n.pa_medi ILike '%'
se x caso dovesse funzionare , aggiungere subquery , altrimente toglierne 1 2 e ripetere l' estrazione :
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ))
_Allopurinolo_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA03' And t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ))
_Febuxostat_cont_ ,' '
FROM nos_002 n WHERE n.pa_medi ILike '%'
Ti saluto , Sergio
X
Cervino- Membro Junior
- Messaggi : 245
Punti : 5283
Voti per importanza dei messaggi : 22
Data d'iscrizione : 03.03.11
Età : 70
Località : Orzivecchi (BS)
Re: Sybase Vs PostgreSQL
Ciao Sergio, ho fatto come mi hai consigliato e la penultima query che hai fatto funziona fino alla seguente subquery, poi mi dà l'errore che ti ho segnalato ieri:
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' '
FROM nos_002 n WHERE n.pa_medi ILike '%'
Ti volevo poi chiedere se al posto del codice del medico si può mettere nome e cognome, una volta fatta l'intera query naturalmente.
Grazie
Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' '
FROM nos_002 n WHERE n.pa_medi ILike '%'
Ti volevo poi chiedere se al posto del codice del medico si può mettere nome e cognome, una volta fatta l'intera query naturalmente.
Grazie
Re: Sybase Vs PostgreSQL
Ciao Renato , dopo aver individuato la subquery che blocca l' estrazione , prova ad eseguirla singolarmente ; in questo caso ad esempio :
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
l' errore dovrebbe ripresentarsi : riesegui la subquey semplificandola progressivamente , fino ad individuare la stringa o funzione che non viene accettata :
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ))
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null )
poi analizzeremo i messaggi di errore restituiti ( comunque se la subquery fosse un' altra o piu' di una , la procedura rimane la medesima ) .
Per il nome al posto del codice medico , credo di si ( almeno in teoria ) ma potro' darTi solo dei suggerimenti in quanto il mio MillePS è MonoUtente .
PS : ho corretto corretto alcune imprecisioni nei codici ICD9 ed eliminato 2 subquery doppie nella query postata il 29/05/15
Ti saluto , Sergio
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
l' errore dovrebbe ripresentarsi : riesegui la subquey semplificandola progressivamente , fino ad individuare la stringa o funzione che non viene accettata :
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ))
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null )
poi analizzeremo i messaggi di errore restituiti ( comunque se la subquery fosse un' altra o piu' di una , la procedura rimane la medesima ) .
Per il nome al posto del codice medico , credo di si ( almeno in teoria ) ma potro' darTi solo dei suggerimenti in quanto il mio MillePS è MonoUtente .
PS : ho corretto corretto alcune imprecisioni nei codici ICD9 ed eliminato 2 subquery doppie nella query postata il 29/05/15
Ti saluto , Sergio
Cervino- Membro Junior
- Messaggi : 245
Punti : 5283
Voti per importanza dei messaggi : 22
Data d'iscrizione : 03.03.11
Età : 70
Località : Orzivecchi (BS)
Re: Sybase Vs PostgreSQL
Questa mi funziona aggiunta a tutta la parte funzionante della query del precedente post purchè levi la riga
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' ':
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
Ovviamente funzionano tutte e tre le parti della query purché non aggiunga la solita stringa ' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' ' poiché mi dà errore di sintassi.
Grazie
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' ':
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
Ovviamente funzionano tutte e tre le parti della query purché non aggiunga la solita stringa ' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' ' poiché mi dà errore di sintassi.
Grazie
Re: Sybase Vs PostgreSQL
ho provato con 2 nuovi metodi. Con Sybase entrambi funzionano. Ma ignoro cosa succede con postgres.Chiedo a Renato (o a chi a postgres) di provarli. Sono solo test incompleti e con dati non controllati. Se uno dei 2 funzionasse si potrà implementare con i dati che mancano.
Altrimenti...ciccia
test1
Select p.sesso,
count(*)as assistiti,
con_uricemia,
g1_0_40,g2_41_65,g3_M_65
FROM
(Select p.sesso, COUNT(distinct a.codice)as con_uricemia
From v_pazienti p,cart_accert a Where a.ac_des = 'URICEMIA'
and a.ac_val is not null and a.codice=p.codice
group by p.sesso)sq1
right outer JOIN V_pazienti p ON p.sesso=sq1.sesso,
(Select p.sesso, COUNT(distinct a.codice)as g1_0_40
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia' AND a.ac_val >7
and a.codice=p.codice and YEARS(p.datanasc, Today()) <=40
group by p.sesso)sq2
right outer JOIN V_pazienti p ON p.sesso=sq2.sesso,
(Select p.sesso, COUNT(distinct a.codice)as g2_41_65
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia' AND a.ac_val >7
and a.codice=p.codice and YEARS(p.datanasc, Today()) Between '41' AND '65'
group by p.sesso)sq3
right outer JOIN V_pazienti p ON p.sesso=sq3.sesso,
(Select p.sesso, COUNT(distinct a.codice)as g3_M_65
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia'
AND a.ac_val >7 and a.codice=p.codice
and YEARS(p.datanasc, Today()) >65
group by p.sesso)sq4
right outer JOIN V_pazienti p ON p.sesso=sq4.sesso
group by p.sesso,con_uricemia, g1_0_40, g2_41_65,g3_M_65
order by 1,2
test2
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia,
p.sesso,COUNT(distinct a.codice)as con_uricemia
From v_pazienti p,cart_accert a Where a.ac_des = 'URICEMIA'
and a.ac_val is not null and a.codice=p.codice
group by fascia,p.sesso)sq2
right outer JOIN V_pazienti p ON p.sesso=sq2.sesso,
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia3, p.sesso, COUNT(distinct a.codice)iperuricemici
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia'AND a.ac_val >7 and a.codice=p.codice
group by fascia3, p.sesso)sq3
right outer JOIN V_pazienti p ON p.sesso=sq3.sesso
where sq3.fascia3=fascia
group by fascia,p.sesso,con_uricemia,iperuricemici
order by 1
Altrimenti...ciccia
test1
Select p.sesso,
count(*)as assistiti,
con_uricemia,
g1_0_40,g2_41_65,g3_M_65
FROM
(Select p.sesso, COUNT(distinct a.codice)as con_uricemia
From v_pazienti p,cart_accert a Where a.ac_des = 'URICEMIA'
and a.ac_val is not null and a.codice=p.codice
group by p.sesso)sq1
right outer JOIN V_pazienti p ON p.sesso=sq1.sesso,
(Select p.sesso, COUNT(distinct a.codice)as g1_0_40
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia' AND a.ac_val >7
and a.codice=p.codice and YEARS(p.datanasc, Today()) <=40
group by p.sesso)sq2
right outer JOIN V_pazienti p ON p.sesso=sq2.sesso,
(Select p.sesso, COUNT(distinct a.codice)as g2_41_65
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia' AND a.ac_val >7
and a.codice=p.codice and YEARS(p.datanasc, Today()) Between '41' AND '65'
group by p.sesso)sq3
right outer JOIN V_pazienti p ON p.sesso=sq3.sesso,
(Select p.sesso, COUNT(distinct a.codice)as g3_M_65
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia'
AND a.ac_val >7 and a.codice=p.codice
and YEARS(p.datanasc, Today()) >65
group by p.sesso)sq4
right outer JOIN V_pazienti p ON p.sesso=sq4.sesso
group by p.sesso,con_uricemia, g1_0_40, g2_41_65,g3_M_65
order by 1,2
test2
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia,
p.sesso,COUNT(distinct a.codice)as con_uricemia
From v_pazienti p,cart_accert a Where a.ac_des = 'URICEMIA'
and a.ac_val is not null and a.codice=p.codice
group by fascia,p.sesso)sq2
right outer JOIN V_pazienti p ON p.sesso=sq2.sesso,
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia3, p.sesso, COUNT(distinct a.codice)iperuricemici
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia'AND a.ac_val >7 and a.codice=p.codice
group by fascia3, p.sesso)sq3
right outer JOIN V_pazienti p ON p.sesso=sq3.sesso
where sq3.fascia3=fascia
group by fascia,p.sesso,con_uricemia,iperuricemici
order by 1
draleo83- Membro Junior
- Messaggi : 225
Punti : 5309
Voti per importanza dei messaggi : 25
Data d'iscrizione : 21.02.11
Re: Sybase Vs PostgreSQL
no nel test 2 ho sbagliato il copia incolla.
mancano le prime 2 righe
SELECT fascia,p.sesso,sq2.con_uricemia,sq3.iperuricemici
FROM
in definitiva
la query è questa
SELECT fascia,p.sesso,sq2.con_uricemia,sq3.iperuricemici
FROM
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia,
p.sesso,COUNT(distinct a.codice)as con_uricemia
From v_pazienti p,cart_accert a Where a.ac_des = 'URICEMIA'
and a.ac_val is not null and a.codice=p.codice
group by fascia,p.sesso)sq2
right outer JOIN V_pazienti p ON p.sesso=sq2.sesso,
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia3, p.sesso, COUNT(distinct a.codice)iperuricemici
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia'AND a.ac_val >7 and a.codice=p.codice
group by fascia3, p.sesso)sq3
right outer JOIN V_pazienti p ON p.sesso=sq3.sesso
where sq3.fascia3=fascia
group by fascia,p.sesso,con_uricemia,iperuricemici
order by 1
mancano le prime 2 righe
SELECT fascia,p.sesso,sq2.con_uricemia,sq3.iperuricemici
FROM
in definitiva
la query è questa
SELECT fascia,p.sesso,sq2.con_uricemia,sq3.iperuricemici
FROM
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia,
p.sesso,COUNT(distinct a.codice)as con_uricemia
From v_pazienti p,cart_accert a Where a.ac_des = 'URICEMIA'
and a.ac_val is not null and a.codice=p.codice
group by fascia,p.sesso)sq2
right outer JOIN V_pazienti p ON p.sesso=sq2.sesso,
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia3, p.sesso, COUNT(distinct a.codice)iperuricemici
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia'AND a.ac_val >7 and a.codice=p.codice
group by fascia3, p.sesso)sq3
right outer JOIN V_pazienti p ON p.sesso=sq3.sesso
where sq3.fascia3=fascia
group by fascia,p.sesso,con_uricemia,iperuricemici
order by 1
draleo83- Membro Junior
- Messaggi : 225
Punti : 5309
Voti per importanza dei messaggi : 25
Data d'iscrizione : 21.02.11
Re: Sybase Vs PostgreSQL
Tutti e due i test con PostgreSQL mi danno errore. Nella tua email ti ho mandato le immagini degli errori.draleo83 ha scritto:no nel test 2 ho sbagliato il copia incolla.
mancano le prime 2 righe
SELECT fascia,p.sesso,sq2.con_uricemia,sq3.iperuricemici
FROM
in definitiva
la query è questa
SELECT fascia,p.sesso,sq2.con_uricemia,sq3.iperuricemici
FROM
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia,
p.sesso,COUNT(distinct a.codice)as con_uricemia
From v_pazienti p,cart_accert a Where a.ac_des = 'URICEMIA'
and a.ac_val is not null and a.codice=p.codice
group by fascia,p.sesso)sq2
right outer JOIN V_pazienti p ON p.sesso=sq2.sesso,
(Select
case
When ((today()-datanasc)/365) < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
When ((today()-datanasc)/365) < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
When ((today()-datanasc)/365) Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
When ((today()-datanasc)/365) >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
When ((today()-datanasc)/365) >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END as fascia3, p.sesso, COUNT(distinct a.codice)iperuricemici
From v_pazienti p,cart_accert a
WHERE a.ac_des ='uricemia'AND a.ac_val >7 and a.codice=p.codice
group by fascia3, p.sesso)sq3
right outer JOIN V_pazienti p ON p.sesso=sq3.sesso
where sq3.fascia3=fascia
group by fascia,p.sesso,con_uricemia,iperuricemici
order by 1
Grazie.
Re: Sybase Vs PostgreSQL
Ciao Leonardo , ho adattato la query che Tu hai suggerito a Renato a PostgreSql e questo è il risultato su un MillePS monoutente di prova : opzione 1 ( utilizzando una vista personalizzata simile a quella disponibile sul Mille.db Sybase ) :
SELECT fascia, p.sesso, sq2.con_uricemia, sq3.iperuricemici
FROM ( SELECT Case
WHEN p.eta < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
WHEN p.eta < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
WHEN p.eta Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN p.eta Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN p.eta >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
WHEN p.eta >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END As fascia , p.sesso , COUNT(distinct a.codice) As con_uricemia
FROM v_pazienti p LEFT Outer JOIN cart_accert a ON a.codice = p.codice
WHERE a.ac_des ILIKE '%Uricemia%' And a.ac_val is not null
GROUP BY fascia , p.sesso) AS sq2 RIGHT Outer JOIN v_pazienti p1 ON p1.sesso = sq2.sesso,
( SELECT Case WHEN p1.eta < 41 AND p1.sesso = 'M' THEN '1: 0-40 anni_M'
WHEN p1.eta < 41 AND p1.sesso='F' THEN '2: 0-40 anni_F'
WHEN p1.eta Between 41 and 65 AND p1.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN p1.eta Between 41 and 65 AND p1.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN p1.eta >65 AND p1.sesso = 'M' THEN '5: >65 anni_M'
WHEN p1.eta >65 AND p1.sesso = 'F' THEN '6: >65 anni_F'
END AS fascia3 , p1.sesso , COUNT( Distinct a1.codice) As iperuricemici
FROM v_pazienti p1 LEFT Outer JOIN cart_accert a1 ON a1.codice = p1.codice
WHERE a1.ac_des ILIKE '%Uricemia%' And Ascii( a1.ac_val ) Between 48 And 57 AND ( To_Number( a1.ac_val , '999D99' ) > 7 And Not Exists ( Select a2.codice From cart_accert a2
Where a2.codice = a1.codice And a2.ac_des ILike '%Uricemia%' And (a2.data_open > a1.data_open Or (a2.data_open = a1.data_open And a2.rowid > a1.rowid)) And a2.ac_val Is Not Null) )
GROUP BY fascia3 , p1.sesso ) AS sq3 RIGHT Outer JOIN v_pazienti p ON p.sesso = sq3.sesso
WHERE sq3.fascia3 = fascia
GROUP BY fascia, p.sesso , con_uricemia , iperuricemici
ORDER BY 1
'1: 0-40 anni_M' 'M' 48 4
'3: 41-65 anni_ M' 'M' 165 9
'4: 41-65 anni_ F' 'F' 155 1
'5: >65 anni_M' 'M' 114 14
'6: >65 anni_F' 'F' 133 5
opzione 2 ( utilizzando una vista personalizzata simile a quella disponibile sul Mille.db Sybase ) :
SELECT fascia, p.sesso, sq2.con_uricemia, sq3.iperuricemici
FROM ( SELECT Case
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END As fascia , p.sesso , COUNT(distinct a.codice) As con_uricemia
FROM v_pazienti p LEFT Outer JOIN cart_accert a ON a.codice = p.codice
WHERE a.ac_des ILIKE '%Uricemia%' And a.ac_val is not null
GROUP BY fascia , p.sesso) AS sq2 RIGHT Outer JOIN v_pazienti p1 ON p1.sesso = sq2.sesso,
( SELECT Case WHEN Days( p2.nascita , Today())*24/8766 < 41 AND p2.sesso = 'M' THEN '1: 0-40 anni_M'
WHEN Days( p2.nascita , Today())*24/8766 < 41 AND p2.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p2.nascita , Today())*24/8766 Between 41 and 65 AND p2.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p2.nascita , Today())*24/8766 Between 41 and 65 AND p2.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p2.nascita , Today())*24/8766 >65 AND p2.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p2.nascita , Today())*24/8766 >65 AND p2. sesso = 'F' THEN '6: >65 anni_F'
END AS fascia3 , p2.sesso , COUNT( Distinct a1.codice) As iperuricemici
FROM v_pazienti p2 LEFT Outer JOIN cart_accert a1 ON a1.codice = p2.codice
WHERE a1.ac_des ILIKE '%Uricemia%' AND a1.ac_val >7
GROUP BY fascia3 , p2.sesso) AS sq3 RIGHT Outer JOIN v_pazienti p ON p.sesso = sq3.sesso
WHERE sq3.fascia3 = fascia
GROUP BY fascia, p.sesso , con_uricemia , iperuricemici
ORDER BY 1
'1: 0-40 anni_M' 'M' 48 3
'3: 41-65 anni_ M' 'M' 165 20
'4: 41-65 anni_ F' 'F' 155 8
'5: >65 anni_M' 'M' 114 22
'6: >65 anni_F' 'F' 133 28
opzione 3 ( utilizzabile anche in MilleUtilità ) :
SELECT fascia, p.sesso, sq2.con_uricemia, sq3.iperuricemici
FROM ( SELECT Case
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END As fascia , p.sesso , COUNT(distinct a.codice) As con_uricemia
FROM pazienti p LEFT Outer JOIN cart_accert a ON a.codice = p.codice
WHERE a.ac_des ILIKE '%Uricemia%' And a.ac_val is not null
GROUP BY fascia , p.sesso) AS sq2 RIGHT Outer JOIN pazienti p1 ON p1.sesso = sq2.sesso,
( SELECT Case WHEN Days( p2.nascita , Today())*24/8766 < 41 AND p2.sesso = 'M' THEN '1: 0-40 anni_M'
WHEN Days( p2.nascita , Today())*24/8766 < 41 AND p2.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p2.nascita , Today())*24/8766 Between 41 and 65 AND p2.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p2.nascita , Today())*24/8766 Between 41 and 65 AND p2.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p2.nascita , Today())*24/8766 >65 AND p2.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p2.nascita , Today())*24/8766 >65 AND p2. sesso = 'F' THEN '6: >65 anni_F'
END AS fascia3 , p2.sesso , COUNT( Distinct a1.codice) As iperuricemici
FROM pazienti p2 LEFT Outer JOIN cart_accert a1 ON a1.codice = p2.codice
WHERE a1.ac_des ILIKE '%Uricemia%' AND a1.ac_val >7
GROUP BY fascia3 , p2.sesso) AS sq3 RIGHT Outer JOIN pazienti p ON p.sesso = sq3.sesso
WHERE sq3.fascia3 = fascia
GROUP BY fascia, p.sesso , con_uricemia , iperuricemici
ORDER BY 1
'1: 0-40 anni_M' 'M' 48 3
'3: 41-65 anni_ M' 'M' 165 20
'4: 41-65 anni_ F' 'F' 155 8
'5: >65 anni_M' 'M' 114 22
'6: >65 anni_F' 'F' 133 28
opzione 4 ( utilizzabile anche in MilleUtilità ) :
SELECT fascia, p.sesso, sq2.con_uricemia, sq3.iperuricemici
FROM ( SELECT Case
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END As fascia , p.sesso , COUNT(distinct a.codice) As con_uricemia
FROM ( pazienti p LEFT Outer JOIN nos_002 n ON p.codice = n.codice ) LEFT Outer JOIN cart_accert a ON a.codice = p.codice
WHERE p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S'))
AND a.ac_des ILIKE '%Uricemia%' And a.ac_val is not null
GROUP BY fascia , p.sesso) AS sq2 RIGHT Outer JOIN pazienti p1 ON p1.sesso = sq2.sesso,
( SELECT Case WHEN Days( p1.nascita , Today())*24/8766 < 41 AND p1.sesso = 'M' THEN '1: 0-40 anni_M'
WHEN Days( p1.nascita , Today())*24/8766 < 41 AND p1.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p1.nascita , Today())*24/8766 Between 41 and 65 AND p1.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p1.nascita , Today())*24/8766 Between 41 and 65 AND p1.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p1.nascita , Today())*24/8766 >65 AND p1.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p1.nascita , Today())*24/8766 >65 AND p1.sesso = 'F' THEN '6: >65 anni_F'
END AS fascia3 , p1.sesso , COUNT( Distinct a1.codice) As iperuricemici
FROM ( pazienti p1 LEFT Outer JOIN nos_002 n ON p1.codice = n.codice ) LEFT Outer JOIN cart_accert a1 ON a1.codice = p1.codice
WHERE p1.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S'))
AND a1.ac_des ILIKE '%Uricemia%' And Ascii( a1.ac_val ) Between 48 And 57 AND ( To_Number( a1.ac_val , '999D99' ) > 7 And Not Exists ( Select a2.codice From cart_accert a2 Where a2.codice = a1.codice And a2.ac_des ILike '%Uricemia%' And (a2.data_open > a1.data_open Or (a2.data_open = a1.data_open And a2.rowid > a1.rowid)) And a2.ac_val Is Not Null) )
GROUP BY fascia3 , p1.sesso ) AS sq3 RIGHT Outer JOIN pazienti p ON p.sesso = sq3.sesso
WHERE sq3.fascia3 = fascia
GROUP BY fascia, p.sesso , con_uricemia , iperuricemici
ORDER BY 1
'1: 0-40 anni_M' 'M' 48 4
'3: 41-65 anni_ M' 'M' 165 9
'4: 41-65 anni_ F' 'F' 155 1
'5: >65 anni_M' 'M' 114 14
'6: >65 anni_F' 'F' 133 5
alcune considerazioni : Tempi di estrazione sempre superiori al minuto con PgAdmin III ( in confronto ai 6 secondi x quella richiesta da Renato adattata a Postgres ) ; inoltre se x caso come nell' esempio un campo è nullo ( '3: 41-65 anni_ F' IperUricemici ) , non viene restituita l' intera riga ( anche se '3: 41-65 anni_ F' con_uricemia non è sicuramente Nullo )
Ti saluto , Sergio
SELECT fascia, p.sesso, sq2.con_uricemia, sq3.iperuricemici
FROM ( SELECT Case
WHEN p.eta < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
WHEN p.eta < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
WHEN p.eta Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN p.eta Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN p.eta >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
WHEN p.eta >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END As fascia , p.sesso , COUNT(distinct a.codice) As con_uricemia
FROM v_pazienti p LEFT Outer JOIN cart_accert a ON a.codice = p.codice
WHERE a.ac_des ILIKE '%Uricemia%' And a.ac_val is not null
GROUP BY fascia , p.sesso) AS sq2 RIGHT Outer JOIN v_pazienti p1 ON p1.sesso = sq2.sesso,
( SELECT Case WHEN p1.eta < 41 AND p1.sesso = 'M' THEN '1: 0-40 anni_M'
WHEN p1.eta < 41 AND p1.sesso='F' THEN '2: 0-40 anni_F'
WHEN p1.eta Between 41 and 65 AND p1.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN p1.eta Between 41 and 65 AND p1.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN p1.eta >65 AND p1.sesso = 'M' THEN '5: >65 anni_M'
WHEN p1.eta >65 AND p1.sesso = 'F' THEN '6: >65 anni_F'
END AS fascia3 , p1.sesso , COUNT( Distinct a1.codice) As iperuricemici
FROM v_pazienti p1 LEFT Outer JOIN cart_accert a1 ON a1.codice = p1.codice
WHERE a1.ac_des ILIKE '%Uricemia%' And Ascii( a1.ac_val ) Between 48 And 57 AND ( To_Number( a1.ac_val , '999D99' ) > 7 And Not Exists ( Select a2.codice From cart_accert a2
Where a2.codice = a1.codice And a2.ac_des ILike '%Uricemia%' And (a2.data_open > a1.data_open Or (a2.data_open = a1.data_open And a2.rowid > a1.rowid)) And a2.ac_val Is Not Null) )
GROUP BY fascia3 , p1.sesso ) AS sq3 RIGHT Outer JOIN v_pazienti p ON p.sesso = sq3.sesso
WHERE sq3.fascia3 = fascia
GROUP BY fascia, p.sesso , con_uricemia , iperuricemici
ORDER BY 1
'1: 0-40 anni_M' 'M' 48 4
'3: 41-65 anni_ M' 'M' 165 9
'4: 41-65 anni_ F' 'F' 155 1
'5: >65 anni_M' 'M' 114 14
'6: >65 anni_F' 'F' 133 5
opzione 2 ( utilizzando una vista personalizzata simile a quella disponibile sul Mille.db Sybase ) :
SELECT fascia, p.sesso, sq2.con_uricemia, sq3.iperuricemici
FROM ( SELECT Case
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END As fascia , p.sesso , COUNT(distinct a.codice) As con_uricemia
FROM v_pazienti p LEFT Outer JOIN cart_accert a ON a.codice = p.codice
WHERE a.ac_des ILIKE '%Uricemia%' And a.ac_val is not null
GROUP BY fascia , p.sesso) AS sq2 RIGHT Outer JOIN v_pazienti p1 ON p1.sesso = sq2.sesso,
( SELECT Case WHEN Days( p2.nascita , Today())*24/8766 < 41 AND p2.sesso = 'M' THEN '1: 0-40 anni_M'
WHEN Days( p2.nascita , Today())*24/8766 < 41 AND p2.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p2.nascita , Today())*24/8766 Between 41 and 65 AND p2.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p2.nascita , Today())*24/8766 Between 41 and 65 AND p2.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p2.nascita , Today())*24/8766 >65 AND p2.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p2.nascita , Today())*24/8766 >65 AND p2. sesso = 'F' THEN '6: >65 anni_F'
END AS fascia3 , p2.sesso , COUNT( Distinct a1.codice) As iperuricemici
FROM v_pazienti p2 LEFT Outer JOIN cart_accert a1 ON a1.codice = p2.codice
WHERE a1.ac_des ILIKE '%Uricemia%' AND a1.ac_val >7
GROUP BY fascia3 , p2.sesso) AS sq3 RIGHT Outer JOIN v_pazienti p ON p.sesso = sq3.sesso
WHERE sq3.fascia3 = fascia
GROUP BY fascia, p.sesso , con_uricemia , iperuricemici
ORDER BY 1
'1: 0-40 anni_M' 'M' 48 3
'3: 41-65 anni_ M' 'M' 165 20
'4: 41-65 anni_ F' 'F' 155 8
'5: >65 anni_M' 'M' 114 22
'6: >65 anni_F' 'F' 133 28
opzione 3 ( utilizzabile anche in MilleUtilità ) :
SELECT fascia, p.sesso, sq2.con_uricemia, sq3.iperuricemici
FROM ( SELECT Case
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END As fascia , p.sesso , COUNT(distinct a.codice) As con_uricemia
FROM pazienti p LEFT Outer JOIN cart_accert a ON a.codice = p.codice
WHERE a.ac_des ILIKE '%Uricemia%' And a.ac_val is not null
GROUP BY fascia , p.sesso) AS sq2 RIGHT Outer JOIN pazienti p1 ON p1.sesso = sq2.sesso,
( SELECT Case WHEN Days( p2.nascita , Today())*24/8766 < 41 AND p2.sesso = 'M' THEN '1: 0-40 anni_M'
WHEN Days( p2.nascita , Today())*24/8766 < 41 AND p2.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p2.nascita , Today())*24/8766 Between 41 and 65 AND p2.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p2.nascita , Today())*24/8766 Between 41 and 65 AND p2.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p2.nascita , Today())*24/8766 >65 AND p2.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p2.nascita , Today())*24/8766 >65 AND p2. sesso = 'F' THEN '6: >65 anni_F'
END AS fascia3 , p2.sesso , COUNT( Distinct a1.codice) As iperuricemici
FROM pazienti p2 LEFT Outer JOIN cart_accert a1 ON a1.codice = p2.codice
WHERE a1.ac_des ILIKE '%Uricemia%' AND a1.ac_val >7
GROUP BY fascia3 , p2.sesso) AS sq3 RIGHT Outer JOIN pazienti p ON p.sesso = sq3.sesso
WHERE sq3.fascia3 = fascia
GROUP BY fascia, p.sesso , con_uricemia , iperuricemici
ORDER BY 1
'1: 0-40 anni_M' 'M' 48 3
'3: 41-65 anni_ M' 'M' 165 20
'4: 41-65 anni_ F' 'F' 155 8
'5: >65 anni_M' 'M' 114 22
'6: >65 anni_F' 'F' 133 28
opzione 4 ( utilizzabile anche in MilleUtilità ) :
SELECT fascia, p.sesso, sq2.con_uricemia, sq3.iperuricemici
FROM ( SELECT Case
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='M' THEN '1: 0-40 anni_M'
WHEN Days( p.nascita , Today())*24/8766 < 41 and p.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p.nascita , Today())*24/8766 Between 41 and 65 AND p.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p.nascita , Today())*24/8766 >65 AND p. sesso = 'F' THEN '6: >65 anni_F'
END As fascia , p.sesso , COUNT(distinct a.codice) As con_uricemia
FROM ( pazienti p LEFT Outer JOIN nos_002 n ON p.codice = n.codice ) LEFT Outer JOIN cart_accert a ON a.codice = p.codice
WHERE p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S'))
AND a.ac_des ILIKE '%Uricemia%' And a.ac_val is not null
GROUP BY fascia , p.sesso) AS sq2 RIGHT Outer JOIN pazienti p1 ON p1.sesso = sq2.sesso,
( SELECT Case WHEN Days( p1.nascita , Today())*24/8766 < 41 AND p1.sesso = 'M' THEN '1: 0-40 anni_M'
WHEN Days( p1.nascita , Today())*24/8766 < 41 AND p1.sesso='F' THEN '2: 0-40 anni_F'
WHEN Days( p1.nascita , Today())*24/8766 Between 41 and 65 AND p1.sesso= 'M' THEN '3: 41-65 anni_ M'
WHEN Days( p1.nascita , Today())*24/8766 Between 41 and 65 AND p1.sesso= 'F' THEN '4: 41-65 anni_ F'
WHEN Days( p1.nascita , Today())*24/8766 >65 AND p1.sesso = 'M' THEN '5: >65 anni_M'
WHEN Days( p1.nascita , Today())*24/8766 >65 AND p1.sesso = 'F' THEN '6: >65 anni_F'
END AS fascia3 , p1.sesso , COUNT( Distinct a1.codice) As iperuricemici
FROM ( pazienti p1 LEFT Outer JOIN nos_002 n ON p1.codice = n.codice ) LEFT Outer JOIN cart_accert a1 ON a1.codice = p1.codice
WHERE p1.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S'))
AND a1.ac_des ILIKE '%Uricemia%' And Ascii( a1.ac_val ) Between 48 And 57 AND ( To_Number( a1.ac_val , '999D99' ) > 7 And Not Exists ( Select a2.codice From cart_accert a2 Where a2.codice = a1.codice And a2.ac_des ILike '%Uricemia%' And (a2.data_open > a1.data_open Or (a2.data_open = a1.data_open And a2.rowid > a1.rowid)) And a2.ac_val Is Not Null) )
GROUP BY fascia3 , p1.sesso ) AS sq3 RIGHT Outer JOIN pazienti p ON p.sesso = sq3.sesso
WHERE sq3.fascia3 = fascia
GROUP BY fascia, p.sesso , con_uricemia , iperuricemici
ORDER BY 1
'1: 0-40 anni_M' 'M' 48 4
'3: 41-65 anni_ M' 'M' 165 9
'4: 41-65 anni_ F' 'F' 155 1
'5: >65 anni_M' 'M' 114 14
'6: >65 anni_F' 'F' 133 5
alcune considerazioni : Tempi di estrazione sempre superiori al minuto con PgAdmin III ( in confronto ai 6 secondi x quella richiesta da Renato adattata a Postgres ) ; inoltre se x caso come nell' esempio un campo è nullo ( '3: 41-65 anni_ F' IperUricemici ) , non viene restituita l' intera riga ( anche se '3: 41-65 anni_ F' con_uricemia non è sicuramente Nullo )
Ti saluto , Sergio
Cervino- Membro Junior
- Messaggi : 245
Punti : 5283
Voti per importanza dei messaggi : 22
Data d'iscrizione : 03.03.11
Età : 70
Località : Orzivecchi (BS)
Re: Sybase Vs PostgreSQL
drtulino ha scritto:Questa mi funziona aggiunta a tutta la parte funzionante della query del precedente post purchè levi la riga
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' ':
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left( te_tipo, 1) = 'C' ))
Ovviamente funzionano tutte e tre le parti della query purché non aggiunga la solita stringa ' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' ' poiché mi dà errore di sintassi.
Grazie
Ciao Renato ; chiedo conferma : tutto il resto della query (riassemblata nelle 3 parti ) funziona , togliendo la stringa :
' Uricemia > 7 => ' _Iperuricemici_ ,
oppure anche altre subquery provocano il blocco dell' estrazione ? provala cosi modificata ( funzionerà ? ):
Select LIST( Distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' Group By n.pa_medi )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' Group By n.pa_medi )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ) Group By n.pa_medi )
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ) Group By n.pa_medi )
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 40.1 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 Group By n.pa_medi )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 40.1 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 Group By n.pa_medi )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between 40.1 And 64.9 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 Group By n.pa_medi )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between 40.1 And 64.9 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 Group By n.pa_medi )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64.9 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 Group By n.pa_medi )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64.9 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 Group By n.pa_medi )
_gruppo3_65_99_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike
'M' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) Group By n.pa_medi )
_gruppo4_0_40_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike
'F' And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) Group By n.pa_medi )
_gruppo4_0_40_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike
'M' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) Group By n.pa_medi )
_gruppo5_41_64_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike
'F' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) Group By n.pa_medi )
_gruppo5_41_64_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike
'M' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) Group By n.pa_medi )
_gruppo6_M_65_99_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike
'F' And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) Group By n.pa_medi )
_gruppo6_M_65_99_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike
'M' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )) Group By n.pa_medi )
_Iperuric_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike
'F' And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )) Group By n.pa_medi )
_Iperuric_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code
ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )) Group By n.pa_medi )
_Iperuric_Ipertensione_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code
ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )) Group By n.pa_medi )
_Iperuric_Ipertensione_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ) Group By n.pa_medi )
_Iperuric_DisLipidemia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ) Group By n.pa_medi )
_Iperuric_DisLipidemia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ) Group By n.pa_medi )
_Iperuric_Diabete_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ) Group By n.pa_medi )
_Iperuric_Diabete_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ) Group By n.pa_medi )
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ) Group By n.pa_medi )
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ) Group By n.pa_medi )
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ) Group By n.pa_medi )
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ) Group By n.pa_medi )
_Iperuric_Demenza_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ) Group By n.pa_medi )
_Iperuric_Demenza_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ))
_Iperuric_Cardiopatia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ) Group By n.pa_medi )
_Iperuric_Cardiopatia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ) Group By n.pa_medi )
_Iperuric_Scomp_Card_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ) Group By n.pa_medi )
_Iperuric_Scomp_Card_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice =
p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ) Group By n.pa_medi )
_Allopurinolo_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today
() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice =
p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA03' And t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ) Group By n.pa_medi )
_Febuxostat_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) )
< 7 Group By n.pa_medi )
_Uricemia_inf_7_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) )
< 6 Group By n.pa_medi )
_Uricemia_inf_6_F_
FROM nos_002 n WHERE n.pa_medi ILike '%'
Ti saluto , Sergio , Orzivecchi BS
Cervino- Membro Junior
- Messaggi : 245
Punti : 5283
Voti per importanza dei messaggi : 22
Data d'iscrizione : 03.03.11
Età : 70
Località : Orzivecchi (BS)
Re: Sybase Vs PostgreSQL
Ciao Sergio la precedente query nelle sue parti funzionava tutta se levavo la stringa ' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' '
Questa ultima mi dà errore: Select LIST(Distinct n.pa_medi) As mmg_code, Select Count(Distinct p.codice) From pazienti p Left Outer Joi
Grazie
Questa ultima mi dà errore: Select LIST(Distinct n.pa_medi) As mmg_code, Select Count(Distinct p.codice) From pazienti p Left Outer Joi
Grazie
Re: Sybase Vs PostgreSQL
Cervino ha scritto:Ciao Leonardo , ho adattato la query che Tu hai suggerito a Renato a PostgreSql e questo è il risultato su un MillePS monoutente di prova :
alcune considerazioni : Tempi di estrazione sempre superiori al minuto con PgAdmin III ( in confronto ai 6 secondi x quella richiesta da Renato adattata a Postgres ) ; inoltre se x caso come nell' esempio un campo è nullo ( '3: 41-65 anni_ F' IperUricemici ) , non viene restituita l' intera riga ( anche se '3: 41-65 anni_ F' con_uricemia non è sicuramente Nullo )
Ti saluto , Sergio
Si. è proprio così. La procedura che intendevo realizzare è più lenta (e questo è abbastanza intuibile :una struttura a tabella di 4-5 righe per 8-9 colonne è naturalmente più lenta di una struttura ad una riga). Ma si parla di ritardi dell’esecuzione di circa 60 secondi e comunque il tempo perduto nell’esecuzione della query si recupera ampiamente con una leggibilità immediata di tutti i dati senza smanettamenti di sorta e con un minor numero di subquery. Ma il problema più serio –anche questo confermato da Sergio- è che quando vado ad inserire le righe per le varie fasce di età, se il relativo parametro della colonna è zero, l’intera riga scompare, impedendo la visualizzazione dei dati delle altre colonne; cioè se voglio estrarre le uricemie per la fascia d’età 40-65 anni e non ci fosse alcun paz rispondente ai requisiti, l’intera riga scompare e così non vengono visualizzati nemmeno i restanti parametri per quella fascia. E questo non dipende dal metodo particolare che ho cercato di utilizzare, ma si verifica anche con i metodi tradizionali. Infatti se vado ad eseguire questa banalissima query per stratificare i paz in base alla fascia d’età
SELECT case
when ((today()-datanasc)/365) <=6 THEN '1: 0-6 anni'
when ((today()-datanasc)/365) BETWEEN 7 AND 14 THEN '2: 7-14 anni'
when ((today()-datanasc)/365) BETWEEN 15 AND 65 THEN '3: 15-65 anni'
when ((today()-datanasc)/365) > 65 THEN '4: oltre 65'
END as Fascia_Eta , count(*) as num_paz
FROM V_Pazienti GROUP BY Fascia_Eta order by 1
la prima fascia d’età (paz inferiori a 6 anni) non viene visualizzata: perché non vi sono nel DB paz inferiori a 6 anni. Per i miei scopi invece occorrerebbe visualizzare anche tale fascia con num_paz= zero . Se qualcuno degli esperti, lavorando sul banalissimo esempio riportato, può darmi qualche dritta per trovare la soluzione, allora, forse, si potrebbe anche organizzare i dati della query di Renato a tabella. Altrimenti ciccia….in fondo … i dati divisi in 2 righe(una per i maschi ,1 per le femmine) vengono fuori ugualmente. Grazie a Sergio e Renato per avermi supportato nel tentativo
Leonardo
draleo83- Membro Junior
- Messaggi : 225
Punti : 5309
Voti per importanza dei messaggi : 25
Data d'iscrizione : 21.02.11
Re: Sybase Vs PostgreSQL
Ciao Renato , non resta che provare a modificare la subquery con la fantasia : proverei con :drtulino ha scritto:Ciao Sergio la precedente query nelle sue parti funzionava tutta se levavo la stringa ' Iperuricemia_cronica => ' _Iperuricemia_cronica_ , ' '
Questa ultima mi dà errore: Select LIST(Distinct n.pa_medi) As mmg_code, Select Count(Distinct p.codice) From pazienti p Left Outer Joi
Grazie
( Select ' Iperuricemia_cronica => ' ) _Iperuricemia_cronica_ ,
( Select ' Iperuricemia_cronica > ' ) _Iperuricemia_cronica_ ,
( Select ' Iperuricemia_cronica --> ' ) _Iperuricemia_cronica_ ,
( Select ' Iperuricemia_cronica ' ) As Iperuricemia_cronica ,
' ' _Iperuricemia_cronica_ ,
e cosi via ; in caso di esito negativo , elimina la subquery .
Quanto al problema molto complesso di ottenere i nomi dei Medici in un MillepS MultiUtente, dovrebbe essere possibile solo usando UNION e ripentendo la seguente query x ogni medico e specifcando una delle due clausole : u.codice_regionale ILIKE '%' AND u.nome ILIKE '%' ma non posso testare altre soluzioni ad es. con WITH forse ) . Come curiosità prova con :
Select InitCap( u.nome) As mmg ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S'
And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M'
And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ) )
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S'
And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F'
And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ) )
_F_con_uricemia_ ,
( Select ' Uricemia > 7 => ' ) _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 40.1 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between
48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open
And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 40.1 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between
48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open
And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between 40.1 And 64.9
And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between
48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open
And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between 40.1 And 64.9
And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between
48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open
And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64.9 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between
48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open
And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64.9 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between
48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open
And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_F_ ,
( Select ' Iperuricemia_cronica => ' ) _Iperuricemia_cronica_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S'
And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M'
And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) )
_gruppo4_0_40_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S'
And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F'
And Days( p.nascita , Today())*24/8766 < 41 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) )
_gruppo4_0_40_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S'
And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M'
And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) )
_gruppo5_41_64_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione =
'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike
'F' And Days( p.nascita , Today())*24/8766 Between 41 And 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) )
_gruppo5_41_64_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S'
And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M'
And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) )
_gruppo6_M_65_99_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S'
And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F'
And Days( p.nascita , Today())*24/8766 > 64 And b.cp_code ILike '274%' /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' ) )
_gruppo6_M_65_99_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S'
And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M'
And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )) )
_Iperuric_M_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_pazpbl b ON b.codice = p.codice Where p.pa_convenzione = 'S'
And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F'
And ( b.cp_code IN ( '274' ) /* And b.cp_cod2 <> '01' */ And Not ( b.pb_status = 'I' And b.modalita ='A' )) )
_Iperuric_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code
ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )) )
_Iperuric_Ipertensione_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And ( b.cp_code ILike '401%' Or b.cp_code
ILike '402%' Or b.cp_code ILike '403%' Or b.cp_code ILike '404%' Or b.cp_code ILike '405%' )) )
_Iperuric_Ipertensione_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ) )
_Iperuric_DisLipidemia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '272%' ) )
_Iperuric_DisLipidemia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ) )
_Iperuric_Diabete_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ) )
_Iperuric_Diabete_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ) )
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '250%' ) )
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ) )
_Iperuric_Ictus_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '436%' ) )
_Iperuric_Ictus_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ) )
_Iperuric_Demenza_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '290%' ) )
_Iperuric_Demenza_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ))
_Iperuric_Cardiopatia_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '414%' ) )
_Iperuric_Cardiopatia_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ) )
_Iperuric_Scomp_Card_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today()
Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And p.codice IN ( Select b.codice From cart_pazpbl
b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '428%' ) )
_Iperuric_Scomp_Card_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca
Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice =
p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C'
And Left( te_tipo, 1) = 'C' ) Group By n.pa_medi )
_Allopurinolo_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca
Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice
And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA03' And t.te_c_flag = 'C'
And Left( te_tipo, 1) = 'C' ) Group By n.pa_medi )
_Febuxostat_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a
Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1
Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) )
< 7 )
_Uricemia_inf_7_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null
Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a
Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1
Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) )
< 6 )
_Uricemia_inf_6_F_
FROM ( pazienti p LEFT Outer JOIN nos_002 n On p.codice = n.codice )
LEFT Outer JOIN v_utenti u On n.pa_medi = u.userid
WHERE u.codice_regionale ILIKE '%' AND u.nome ILIKE '%' AND p.pa_convenzione = 'S'
AND ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) AND p.decesso Is Null
AND Year( p.nascita) Between 1910 And 2015
GROUP BY u.nome
ORDER BY 1
Ti saluto , Sergio
Cervino- Membro Junior
- Messaggi : 245
Punti : 5283
Voti per importanza dei messaggi : 22
Data d'iscrizione : 03.03.11
Età : 70
Località : Orzivecchi (BS)
Re: Sybase Vs PostgreSQL
Ciao Sergio,Cervino ha scritto:Select LIST( distinct n.pa_medi) As mmg_code ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' )
_Assisititi_M_ ,
(Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' )
_Assisititi_F_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'M' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_M_con_uricemia_ ,
( Select Count( Distinct p.codice) From ( pazienti p Left Outer Join nos_002 n On p.codice = n.codice ) Left Outer Join cart_accert a ON a.codice = p.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And Sesso ILike 'F' And ( a.ac_code ILike ' 788' And a.ac_val Is Not Null ))
_F_con_uricemia_ ,
' Uricemia > 7 => ' _Iperuricemici_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 < 41 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo1_0_40_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 Between '41' And '64' And ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo2_41_64_F_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'F' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_F_ ,
' Iperuricemia_cronica => ' _Iperuricemia_cronica_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA01' And t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ))
_Allopurinolo_cont_ ,
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And p.decesso Is Null And p.codice IN ( Select b.codice From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274.9%' ) And p.codice IN ( Select t.codice From cart_terap t Where t.codice = p.codice And t.co_atc ILike 'M04AA03' And t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ))
_Febuxostat_cont_ ,' '
FROM nos_002 n WHERE n.pa_medi ILike '%'
Ti saluto , Sergio
X
ho fatto tutte le prove aggiungendo e togliendo le varie subquery. L'unica subquery che dà errore è la seguente, mentre tutta la query senza questa subquery funziona per intero correttamente (non ho esaminato i valori numerici che mi estrae, per il momento):
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
Considera che la stessa subquery, ma del gruppo _F_ non dà alcun errore (basta che cambi in "And Sesso Ilike la 'F' con la 'M' e mi dà l'errore che ti riporto di seguito).
L'errore che mi dà dice: "il campo numeric causa un owerflow
Un campo con precisione 3 e 0 cifre decimali deve arrotondarsi ad un valore assoluto inferiore a 10^3."
Spero di essere stato chiaro altrimenti chiedi pure.
Grazie.
Re: Sybase Vs PostgreSQL
drtulino ha scritto:Ciao Sergio,
ho fatto tutte le prove aggiungendo e togliendo le varie subquery. L'unica subquery che dà errore è la seguente, mentre tutta la query senza questa subquery funziona per intero correttamente (non ho esaminato i valori numerici che mi estrae, per il momento):
( Select Count( Distinct p.codice) From pazienti p Left Outer Join nos_002 n On p.codice = n.codice Where p.pa_convenzione = 'S' And Sesso ILike 'M' And ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S')) And Days( p.nascita , Today())*24/8766 > 64 And
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) >7 )
_gruppo3_65_99_M_ ,
Considera che la stessa subquery, ma del gruppo _F_ non dà alcun errore (basta che cambi in "And Sesso Ilike la 'F' con la 'M' e mi dà l'errore che ti riporto di seguito).
L'errore che mi dà dice: "il campo numeric causa un owerflow
Un campo con precisione 3 e 0 cifre decimali deve arrotondarsi ad un valore assoluto inferiore a 10^3."
Spero di essere stato chiaro altrimenti chiedi pure.
Grazie.
Ciao Renato , sei stato chiarissimo : la funzione to_number non è facilmente intuitiva ma semplificando serve a riconoscere un valore numerico all' interno di una stringa al fine di estrarlo ; l' errore di Overflow indica che la funzione ha rilevato in ac_val un numero con piu' di 3 cifre : un errore di digitazione relativamente comune in MW quando si usa la tastiera x i numeri al posto del tastierino ; il valore 11.35 ( con il punto ) viene correttamente riconosciuto ma 11,35 ( con la virgola ) no in quanto la funzione restituisce il valore 1135 ma essendo la parte intera stata limitata intenzionalmante a 3 cifre ( x l' Uricemia , Creatinina ad esempio in verità ne basterebbero 2 ) ecco comparire l' errore di Overflow ; questo al fine di verificare l' integrità dei dati e di avere dati omogenei nelle analisi statistiche ; la parte decimale è meno importante salvo nell' analisi di quantità infinitesimali ( é necessario usare un valore numerico del campo ac_val in questa estrazione , al fine di individuare correttamente i valori di Uricemia > 7 ) . Per esemplificare :
Select To_Number( ' 12gh345,as6789' , '99999.99999999' ) ;
--> ERROR: numeric field overflow DETAIL: A field with precision 5, scale 0 must round to an absolute value less than 10^5.
Select To_Number( ' 12gh345,as6789' , '999999999.99999999' ) ; --> 123456789
Select To_Number( ' 12gh345.as6789' , '99999.99999999' ) ; --> 12345.6789
Select Round(To_Number( ' 12gh345.as6789' , '99999.99999999' ), 2 ) ; --> 12345.68
Soluzioni : 1) Correggere eventuali errori di digitazione ( ottimale ) ; x evidenziarli usare la query :
Select Distinct u.nome As mmg , p.cognome , p.nome , p.sesso , Days( p.nascita , Today())*24/8766 As eta ,
( Select a.ac_val From cart_accert a Where a.codice = p.codice And a.ac_code ILike ' 788' And a.data_open < Today() And a.ac_val Is Not Null
And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open
And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) )
_Ac_Ur_
FROM ( pazienti p LEFT Outer JOIN nos_002 n ON p.codice = n.codice )
LEFT Outer JOIN v_utenti u ON u.userid = n.pa_medi
WHERE p.pa_convenzione = 'S' AND ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S'))
AND p.decesso Is Null AND Sesso ILike '%' AND ( Case WHEN p.sesso = 'M' THEN
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) > 7 ELSE ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) > 6 END
OR ( Select Year( Max( b.data_open)) From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274%' And Not ( b.pb_status = 'I' And b.modalita ='A' ) ) > 0 )
Order By 6 , 1 , 2
2) provare ad aggiungere una cifra ( o eventualmente piu' cifre) al valore ac_val ,
utillizzando : To_Number( a.ac_val , '9999D99' )
oppure To_Number( a.ac_val , '9999.99' )
3) provare a sostituire To_Number( a.ac_val , '9999D99' ) con :
To_Number( Case When Position ( ',' in a.ac_val ) > 0 Then Overlay( a.ac_val placing '.' From Position ( ',' in a.ac_val ) For 1 ) Else a.ac_val End , '999.99' )
( Sostituire in blocco Funzioni e/o Clausole nelle query è molto semplice e facile con : Blocco Note / Notepad --> Edit / Modifica --> Replace / Sostituisci --> utilizzare i campi Trova / Find e Replace / Rimpiazza )
Ti saluto , Sergio
Cervino- Membro Junior
- Messaggi : 245
Punti : 5283
Voti per importanza dei messaggi : 22
Data d'iscrizione : 03.03.11
Età : 70
Località : Orzivecchi (BS)
Re: Sybase Vs PostgreSQL
Un altro approccio. Speriamo funzioni anche con postgres . i dati sono gli stessi ( almeno così mi sembra), solo che sono disposti in verticale. Ma Se vuoi metterli in orizzontale basta salvare in excel, e con il comando copia/incolla speciale/trasponi li avrai in orizzontale. Manca il codice medico che può essere inutile: avendo usato V_pazienti verranno estratti solo i paz del medico che ha aperto mille Utilità. Se manca qualche parametro significa che NON esistono paz con quel parametro , cioè se non comparisse la riga dell' ictus significa che non esistono paz con problema iperuricemia+ ictus . E' dovuto al fatto che Group by estrae il gruppo solo se questo esiste. La tabella risultante Potrebbe anche essere compattata molto di più ,ma l'estrazione si rallenterebbe alquanto (una decina di minuti) e non so quanto ne valga la pena
Ciao e FORZA JUVE .stasera ci divertiremo (almeno spero)
Leonardo
Select '1. Assistiti ' as tipo,sesso, count(*)num
from V_pazienti group by sesso
UNION
Select '2. con misuraz' as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a Where a.ac_des = 'URICEMIA' and a.ac_val is not null and a.codice=p.codice group by p.sesso
UNION
Select '3. iperuricemici: gruppo 1_0_40'as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a WHERE a.ac_des ='uricemia' AND a.ac_val >7 and a.codice=p.codice and Days( p.datanasc , Today())*24/8766 <=40 group by p.sesso
UNION
Select '4. iperuricemici: gruppo 2_41_65'as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a WHERE a.ac_des ='uricemia' AND a.ac_val >7 and a.codice=p.codice and Days( p.datanasc , Today())*24/8766 between 41 and 65 group by p.sesso
UNION
Select '5. iperuricemici: gruppo 3 > 65'as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a WHERE a.ac_des ='uricemia' AND a.ac_val >7 and a.codice=p.codice and Days( p.datanasc , Today())*24/8766 > 65 group by p.sesso
UNION
Select '6. iperuric_cronica: gruppo 4_0_40' as tipo, p.sesso,COUNT(distinct pb.codice)
FROM cart_pazpbl pb , v_pazienti p WHERE p.codice=pb.codice AND Days( p.datanasc , Today())*24/8766 <41 AND pb.codice IN (select codice FROM cart_pazpbl WHERE Cp_Code like '274%' )
group by p.sesso
UNION
Select '7. iperuric_cronica: gruppo 5_41_65' as tipo, p.sesso,COUNT(distinct pb.codice)
FROM cart_pazpbl pb , v_pazienti p WHERE p.codice=pb.codice AND Days( p.datanasc , Today())*24/8766 BETWEEN 41 AND 65 AND pb.codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' ) group by p.sesso
UNION
Select '8. iperuric_cronica: gruppo 6_>65' as tipo, p.sesso,COUNT(distinct pb.codice)
FROM cart_pazpbl pb , v_pazienti p WHERE p.codice=pb.codice AND Days( p.datanasc , Today())*24/8766 > 65 AND pb.codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' ) group by p.sesso
UNION
select case
When Pb.cp_code BETWEEN '401%' AND '405%' then '9. anche _ ipertensione'
when pb.cp_code like '274%' then '_10. anche _ dislipidemia'
when Pb.cp_code LIKE '250%' then '_11. anche _ diabete'
when Pb.cp_code LIKE '436%' then '_12. anche _ ictus'
when Pb.cp_code LIKE '290%' then '_13. anche _ demenza'
when Pb.cp_code LIKE '414%' then '_14. anche _ cardiopatia'
when Pb.cp_code LIKE '428%' then '_15. anche _ scompenso'
else '_16. anche _ ALTRI_prob'
end as tipo, p.sesso,count ( p.codice) num
FROM V_pazienti p ,cart_pazpbl pb where p.codice =pb.codice
and p.codice in (select codice from cart_pazpbl where Cp_Code LIKE '274%') group by tipo,sesso
UNION
Select '_17. Allopurinolo_C ' as tipo, sesso, COUNT(distinct codice)
FROM V_pazienti
Where codice IN (SELECT codice from cart_pazpbl WHERE Cp_Code LIKE '274%')
AND codice IN (select codice FROM cart_terap t where t.co_atc like 'M04AA01' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ) group by sesso
UNION
Select '_18. Febuxostat_C ' as tipo, sesso, COUNT(distinct codice)
FROM V_pazienti Where codice IN (SELECT codice from cart_pazpbl WHERE Cp_Code LIKE '274%')
AND codice IN (select codice FROM cart_terap t where t.co_atc like 'M04AA03' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ) group by sesso
UNION
Select '_19. con uricemia<6'as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a WHERE a.ac_des ='uricemia' AND a.ac_val <6 and a.codice=p.codice
group by p.sesso
order by 1
Ciao e FORZA JUVE .stasera ci divertiremo (almeno spero)
Leonardo
Select '1. Assistiti ' as tipo,sesso, count(*)num
from V_pazienti group by sesso
UNION
Select '2. con misuraz' as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a Where a.ac_des = 'URICEMIA' and a.ac_val is not null and a.codice=p.codice group by p.sesso
UNION
Select '3. iperuricemici: gruppo 1_0_40'as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a WHERE a.ac_des ='uricemia' AND a.ac_val >7 and a.codice=p.codice and Days( p.datanasc , Today())*24/8766 <=40 group by p.sesso
UNION
Select '4. iperuricemici: gruppo 2_41_65'as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a WHERE a.ac_des ='uricemia' AND a.ac_val >7 and a.codice=p.codice and Days( p.datanasc , Today())*24/8766 between 41 and 65 group by p.sesso
UNION
Select '5. iperuricemici: gruppo 3 > 65'as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a WHERE a.ac_des ='uricemia' AND a.ac_val >7 and a.codice=p.codice and Days( p.datanasc , Today())*24/8766 > 65 group by p.sesso
UNION
Select '6. iperuric_cronica: gruppo 4_0_40' as tipo, p.sesso,COUNT(distinct pb.codice)
FROM cart_pazpbl pb , v_pazienti p WHERE p.codice=pb.codice AND Days( p.datanasc , Today())*24/8766 <41 AND pb.codice IN (select codice FROM cart_pazpbl WHERE Cp_Code like '274%' )
group by p.sesso
UNION
Select '7. iperuric_cronica: gruppo 5_41_65' as tipo, p.sesso,COUNT(distinct pb.codice)
FROM cart_pazpbl pb , v_pazienti p WHERE p.codice=pb.codice AND Days( p.datanasc , Today())*24/8766 BETWEEN 41 AND 65 AND pb.codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' ) group by p.sesso
UNION
Select '8. iperuric_cronica: gruppo 6_>65' as tipo, p.sesso,COUNT(distinct pb.codice)
FROM cart_pazpbl pb , v_pazienti p WHERE p.codice=pb.codice AND Days( p.datanasc , Today())*24/8766 > 65 AND pb.codice IN
(select codice FROM cart_pazpbl WHERE Cp_Code like '274%' ) group by p.sesso
UNION
select case
When Pb.cp_code BETWEEN '401%' AND '405%' then '9. anche _ ipertensione'
when pb.cp_code like '274%' then '_10. anche _ dislipidemia'
when Pb.cp_code LIKE '250%' then '_11. anche _ diabete'
when Pb.cp_code LIKE '436%' then '_12. anche _ ictus'
when Pb.cp_code LIKE '290%' then '_13. anche _ demenza'
when Pb.cp_code LIKE '414%' then '_14. anche _ cardiopatia'
when Pb.cp_code LIKE '428%' then '_15. anche _ scompenso'
else '_16. anche _ ALTRI_prob'
end as tipo, p.sesso,count ( p.codice) num
FROM V_pazienti p ,cart_pazpbl pb where p.codice =pb.codice
and p.codice in (select codice from cart_pazpbl where Cp_Code LIKE '274%') group by tipo,sesso
UNION
Select '_17. Allopurinolo_C ' as tipo, sesso, COUNT(distinct codice)
FROM V_pazienti
Where codice IN (SELECT codice from cart_pazpbl WHERE Cp_Code LIKE '274%')
AND codice IN (select codice FROM cart_terap t where t.co_atc like 'M04AA01' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ) group by sesso
UNION
Select '_18. Febuxostat_C ' as tipo, sesso, COUNT(distinct codice)
FROM V_pazienti Where codice IN (SELECT codice from cart_pazpbl WHERE Cp_Code LIKE '274%')
AND codice IN (select codice FROM cart_terap t where t.co_atc like 'M04AA03' AND t.te_c_flag = 'C' And Left(te_tipo, 1) = 'C' ) group by sesso
UNION
Select '_19. con uricemia<6'as tipo, p.sesso, COUNT(distinct a.codice)
From v_pazienti p,cart_accert a WHERE a.ac_des ='uricemia' AND a.ac_val <6 and a.codice=p.codice
group by p.sesso
order by 1
draleo83- Membro Junior
- Messaggi : 225
Punti : 5309
Voti per importanza dei messaggi : 25
Data d'iscrizione : 21.02.11
Re: Sybase Vs PostgreSQL
Ciao Sergio, ho sostituito il numero precedente con il seguente 9999D99 e funziona. Il problema che mi si pone è che non mi seleziona i medici del gruppo, pur aggiungendo il codice identificativo di ciascun medico. Mi estrae sempre tutti i dati insieme per tutti i MMG della Medicina di Gruppo.Cervino ha scritto:Ciao Renato , sei stato chiarissimo : la funzione to_number non è facilmente intuitiva ma semplificando serve a riconoscere un valore numerico all' interno di una stringa al fine di estrarlo ; l' errore di Overflow indica che la funzione ha rilevato in ac_val un numero con piu' di 3 cifre : un errore di digitazione relativamente comune in MW quando si usa la tastiera x i numeri al posto del tastierino ; il valore 11.35 ( con il punto ) viene correttamente riconosciuto ma 11,35 ( con la virgola ) no in quanto la funzione restituisce il valore 1135 ma essendo la parte intera stata limitata intenzionalmante a 3 cifre ( x l' Uricemia , Creatinina ad esempio in verità ne basterebbero 2 ) ecco comparire l' errore di Overflow ; questo al fine di verificare l' integrità dei dati e di avere dati omogenei nelle analisi statistiche ; la parte decimale è meno importante salvo nell' analisi di quantità infinitesimali ( é necessario usare un valore numerico del campo ac_val in questa estrazione , al fine di individuare correttamente i valori di Uricemia > 7 ) . Per esemplificare :
Select To_Number( ' 12gh345,as6789' , '99999.99999999' ) ;
--> ERROR: numeric field overflow DETAIL: A field with precision 5, scale 0 must round to an absolute value less than 10^5.
Select To_Number( ' 12gh345,as6789' , '999999999.99999999' ) ; --> 123456789
Select To_Number( ' 12gh345.as6789' , '99999.99999999' ) ; --> 12345.6789
Select Round(To_Number( ' 12gh345.as6789' , '99999.99999999' ), 2 ) ; --> 12345.68
Soluzioni : 1) Correggere eventuali errori di digitazione ( ottimale ) ; x evidenziarli usare la query :
Select Distinct u.nome As mmg , p.cognome , p.nome , p.sesso , Days( p.nascita , Today())*24/8766 As eta ,
( Select a.ac_val From cart_accert a Where a.codice = p.codice And a.ac_code ILike ' 788' And a.data_open < Today() And a.ac_val Is Not Null
And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open
And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) )
_Ac_Ur_
FROM ( pazienti p LEFT Outer JOIN nos_002 n ON p.codice = n.codice )
LEFT Outer JOIN v_utenti u ON u.userid = n.pa_medi
WHERE p.pa_convenzione = 'S' AND ( n.pa_drevoca Is Null Or n.pa_drevoca > Today() Or ( n.pa_drevoca Between Date( Today())-365 And Today() And motivo_revoca = 'S'))
AND p.decesso Is Null AND Sesso ILike '%' AND ( Case WHEN p.sesso = 'M' THEN
( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) > 7 ELSE ( Select To_Number( a.ac_val , '999D99' ) From cart_accert a Where a.codice = p.codice And ( a.ac_code ILike ' 788' And a.data_open < Today() And Ascii( a.ac_val ) Between 48 And 57 ) And Not Exists ( Select a1.codice From cart_accert a1 Where a1.codice = a.codice And a1.ac_code ILike ' 788' And (a1.data_open > a.data_open Or (a1.data_open = a.data_open And a1.rowid > a.rowid)) And a1.ac_val Is Not Null) ) > 6 END
OR ( Select Year( Max( b.data_open)) From cart_pazpbl b Where b.codice = p.codice And b.cp_code ILike '274%' And Not ( b.pb_status = 'I' And b.modalita ='A' ) ) > 0 )
Order By 6 , 1 , 2
2) provare ad aggiungere una cifra ( o eventualmente piu' cifre) al valore ac_val ,
utillizzando : To_Number( a.ac_val , '9999D99' )
oppure To_Number( a.ac_val , '9999.99' )
3) provare a sostituire To_Number( a.ac_val , '9999D99' ) con :
To_Number( Case When Position ( ',' in a.ac_val ) > 0 Then Overlay( a.ac_val placing '.' From Position ( ',' in a.ac_val ) For 1 ) Else a.ac_val End , '999.99' )
( Sostituire in blocco Funzioni e/o Clausole nelle query è molto semplice e facile con : Blocco Note / Notepad --> Edit / Modifica --> Replace / Sostituisci --> utilizzare i campi Trova / Find e Replace / Rimpiazza )
Ti saluto , Sergio
Grazie.
Pagina 1 di 2 • 1, 2
Argomenti simili
» query sybase per LAMA e glaucoma
» Passaggio a PostgreSQL
» ESTRAZIONE RCV - MODIFICA VECCHIA QUERY SYBASE
» sondaggio sybase postgres
» Postgresql: impressioni a caldo
» Passaggio a PostgreSQL
» ESTRAZIONE RCV - MODIFICA VECCHIA QUERY SYBASE
» sondaggio sybase postgres
» Postgresql: impressioni a caldo
Permessi in questa sezione del forum:
Non puoi rispondere agli argomenti in questo forum.