Utilizzo ASP e MySQL, questa è la query che mi estrae i recordset che mi interessano:
codice:
select es as es, `codice n` as cn, `descrizione n` as dn, `descrizione l` as dl, substring_index(LN,'-',1) as r, sum(if(dove=1,1,0)) as intTotalB, sum(if(dove=2,1,0)) as intTotalL, count(substring_index(LN,'-',1)) as q from ( select es, id_Z, `codice n`, `descrizione no`, data, `descrizione l`, LN, 1 as dove from tbl_b as B where 1 and ( data between '2010-01-01' and '2010-06-23' and LN > '0' and es LIKE '%I%' ) union all select iddtes, id_Z, cp, imp, data_evento, substring_index(LN_MT,'-',-1), LN_MT, 2 as dove from tbl_l as L where 1 and ( data_evento between '2010-01-01' and '2010-06-23' and LN_MT > '0' and iddtes LIKE '%I%' ) ) as tab group by r having q > 3 order by q desc, `descrizione l` asc LIMIT 0, 25