0% found this document useful (0 votes)
8 views3 pages

TH CSDL Lab6

Uploaded by

quanpogba888
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

TH CSDL Lab6

Uploaded by

quanpogba888
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

--C1:

alter table nguoi_an add primary key(ten);


alter table an add primary key (ten, pizza);
alter table lui_toi add primary key (ten, quanPizza);
alter table phuc_vu add primary key(quanPizza, pizza);
alter table an add foreign key (ten) references nguoi_an(ten);
alter table lui_toi add foreign key (ten) references nguoi_an(ten);

alter table phuc_vu add check (gia>0);


--C2:
select distinct pizza
from phuc_vu
where quanPizza = 'Pizza Hut';
--C3:
select distinct pizza
from phuc_vu;
--C4:
select quanPizza
from phuc_vu
where pizza like '%m%';
--C5:
select nguoi_an.ten, tuoi
from nguoi_an join lui_toi on nguoi_an.ten = lui_toi.ten
where quanPizza = 'Dominos'
order by tuoi desc;
--C6:
select quanPizza, count(pizza) soBanhPizza
from phuc_vu
group by quanPizza
order by count(pizza) desc;
--C7:
select distinct quanPizza
from phuc_vu
where gia = (select max(gia) from phuc_vu);
--C8:
select distinct quanPizza
from phuc_vu
where pizza in (select pizza
from an
where ten = 'Ian');
--C9:
select distinct quanPizza
from phuc_vu
where pizza not in (select pizza
from an
where ten = 'Eli');
--C10:
select quanPizza
from phuc_vu
except
select distinct quanPizza
from phuc_vu
where pizza not in (select pizza
from an
where ten = 'Eli');
--C11:
--Cach 1:
select distinct quanPizza
from phuc_vu
where gia > all (select gia
from phuc_vu
where quanPizza = 'New York Pizza');
--Cach 2:
select distinct quanPizza
from phuc_vu
where gia > (select max(gia)
from phuc_vu
where quanPizza = 'New York Pizza');
--C12:
select quanPizza
from phuc_vu
except
select quanPizza
from phuc_vu
where gia >= 10.000;
--C13:
--Cach 1:
select pizza
from phuc_vu
where quanPizza = 'New York Pizza'
and pizza in (select pizza
from phuc_vu
where quanPizza = 'Dominos');
--Cach 2:
select pizza
from phuc_vu
where quanPizza = 'New York Pizza'
intersect
select pizza
from phuc_vu
where quanPizza = 'Dominos';
--C14:
--Cach 1:
select pizza
from phuc_vu
where quanPizza = 'Little Caesars'
and pizza not in (select pizza
from phuc_vu
where quanPizza = 'Pizza Hut');

--Cach 2:
select pizza
from phuc_vu
where quanPizza = 'Little Caesars'
except
select pizza
from phuc_vu
where quanPizza = 'Pizza Hut';
--C15:
select quanPizza
from phuc_vu
group by quanPizza
having count(pizza) = (select count(distinct pizza) from phuc_vu);
--C16:
select quanPizza, count(pizza) soPizzaGusThich
from phuc_vu
where pizza in (select pizza
from an
where ten ='Gus')
group by quanPizza
having count(pizza) >= 2;
--C17:
select quanPizza, count(pizza) soPizzaIanThich
from phuc_vu
where pizza in (select pizza
from an
where ten ='Ian')
group by quanPizza
having count(pizza) >= (select count(pizza) from an where ten='Ian');
--C18:
select ten
from lui_toi
group by ten
having count(quanPizza) >=3;
--C19:
select quanPizza, count(pizza) soPizza
from phuc_vu
group by quanPizza;
--C20:
--Tim ten nguoi an thich an tat ca banh ma Hil thich
select a1.ten
from an a1, an a2
where a1.pizza = a2.pizza and a1.ten <> a2.ten and a2.ten='Hil'
group by a1.ten
having count(*) = (select count(pizza)
from an
where ten = 'Hil');
--Tim ten nguoi an thich an it nhat 1 banh ma Hil thich
select distinct a1.ten
from an a1, an a2
where a1.pizza = a2.pizza and a2.ten ='Hil' and a1.ten <> a2.ten;

You might also like