You are on page 1of 3

/*Funcionamiento de una peticion estandar

*/
select *
from prescription
where medicament like '%doliprane%';
/*Funcionamiento de ORDER BY*/
select *
from prescription
where medicament like '%ventoline%'
ORDER BY duree DESC;
/*Funcionamiento de restriccion AND*/
select *
from prescription
where medicament like '%ventoline%' and duree > 90;
/*Funcionamiento de restricciones con parentesis*/
select *
from prescription
where medicament like '%ventoline%' and (duree > 90 or posologie > 6);
/*Funcionamiento de EXIST*/
select *
from prescription
where exists (select *
from prescription
where medicament like '%ventoline%' and duree > 90);
select *
from prescription
where exists (select *
from prescription
where medicament like '%ventoline%' and duree > 500);
/*Funcionamiento de INNER JOIN estandar*/
select prix
from visite v
inner join prescription p
on p.medecin = v.medecin and p.patient = v.patient and p.date_visite = v.date_vi
site;
/*Funcionamientos de INNER JOIN complejos*/
select p.nom nom_patient, m.nom nom_medecin
from patient p
join visite v
on p.patient_id = v.patient
join medecin m
on v.medecin = m.medecin_id
where date_visite = to_date('15/01/2012','dd/mm/yyyy');
select p2.nom, p2.prenom, p1.numsecu, p1.nom, p1.prenom
from patient p1
inner join patient p2
on p2.rattachement = p1.patient_id
where p2.rattachement is not NULL;
select p.nom, m.nom
from patient p
join medecin m
on p.medecin_referent = m.medecin_id;
select p.nom, m.nom
from patient p
left outer join medecin m
on p.medecin_referent = m.medecin_id;
select nom
from patient p
join visite v
on p.patient_id = v.patient
where p.medecin_referent = v.medecin and v.date_visite = to_date('15/01/2012','d
d/mm/yyyy');
select p.nom, m.nom
from patient p join visite v
on p.patient_id=v.patient
join medecin m
on v.medecin=m.medecin_id
where v.medecin=p.medecin_referent and date_visite = to_date('15/1/2012','dd/mm/
yyyy');
/*Funcionamiento de NEGACION y LISTAS*/
select *
from medecin
where specialite not like 'generaliste';
select *
from patient
where medecin_referent is NULL;
select *
from patient
where patient_id not in
(select patient
from visite);
select *
from prescription
where prescription_id not in
(select prescription_id
from prescription
where medicament like '%doliprane%');
select distinct p.nom
from patient p
join visite v
on p.patient_id = v.patient
where (v.medecin, v.patient, v.date_visite) not in
(select medecin, patient,
date_visite from prescription);
/*Funcionamiento de AGREGACION*/
select count(medecin_id)
from medecin;
select count(distinct specialite)
from medecin;
select specialite, count(medecin_id)
from medecin
group by specialite;
select distinct p1.*
from patient p1
join patient p2
on p2.rattachement = p1.patient_id
where p2.rattachement is not NULL
order by p1.patient_id asc;