You are on page 1of 7

--Câu 1--

select idLoai
from may
where idmay = 'p8'
--Câu 2--
select tenloai
from Loai
where idLoai = 'UNIX';
-- Câu 3--
select Phong.tenphong, Phong.IP, Phong.MP
from Phong, may
where Phong.MP = may.MP and (idLoai = 'UNIX' or idLoai = 'PCWS');
-- Câu 4--
select Distinct Phong.tenphong, Phong.IP, Phong.MP
from Phong, May
where Phong.MP = may.MP and
(idLoai = 'UNIX' or idLoai = 'PCWS') and May.IP = '130.120.80'
order by MP;
-- Câu 5--
select count(*) from Caidat where idMay = 'p6';
-- Câu 6--
select count(*) from Caidat where idPM = 'log1';
-- Câu 7--
select tenmay, IP
from May
where idLoai = 'TX';
-- Câu 8--
select idmay, count (*)
from caidat
group by idmay;
--Câu 9--
select MP, count(*) as So_may
from May
group by MP;
--Câu 10--
select idMay, count(*)
from caidat
group by idMay;
--Câu 11--
select avg(gia)
from Phanmem
where idloai= 'UNIX';
--Câu 12--
select max(ngaymua) as Ngay_mua_gan_nhat
from Phanmem;
--Câu 13--
select IdMay, count(*)
from caidat group by idMay
having count(*)>=2;
--Câu 14--
select count(*)
from (select idMay
from caidat group by idMay
having count(*)>=2
);
--Câu 15--
Cach 1
select idLoai from Loai
minus
select idLoai from May;
Cach 2
select L.idLoai
from Loai L
left join May M on L.idLoai = M.idLoai
where M.idLoai IS NULL;
--Cau 16--
select idLoai from Loai
intersect
select idLoai from May;
--Cau 17--
Cach 1
select idLoai from May
minus
select idLoai from Phanmem;
Cach 2
select distinct M.idLoai
from May M
left join Phanmem PM on M.idLoai = PM.idLoai
where PM.idLoai is NULL;
--Cau 18--
select IP
from May
where idMay in (
select idMay
from Caidat
where idPM = 'log6'
);
--Cau 19--
select IP
from May
where idMay in (
select idMay
from Caidat
where idPM in (
select idPM
from Phanmem
where tenPM = 'Oracle 8'
)
);
--Cau 20--
select tenKhuVuc
from KHUVUC
where IP in
(
select IP
from May
where (idloai='TX')
group by IP
having count(*) = 3
);
-- Cau 21--
select tenPhong
from Phong
where MP in (
select MP
from May
where idMay in (
select idMay
from Caidat
where idPM = (
select idPM
from Phanmem
where tenPM = 'Oracle 6'
)
group by idMay
having COUNT (*) >= 1
)
);
-- Cau 22--
SELECT tenPM
FROM phanmem
WHERE ngaymua = (
SELECT MAX (ngaymua) ngay_mua_gan_nhat
FROM Phanmem
);
--Cau 23--
SELECT tenPM
FROM Phanmem
WHERE ngaymua = (
SELECT MAX (ngaymua) ngay_mua_gan_nhat
FROM Phanmem
);
--Cau 24--
FROM May JOIN Caidat ON May.idMay = Caidat.idMay
JOIN Phanmem ON Caidat.idPM = Phanmem.idPM
WHERE tenPM = 'Oracle 8'
--Câu 25--
SELECT tenKhuvuc
FROM Khuvuc
JOIN May ON May.IP = Khuvuc.IP
WHERE May.idloai = 'TX'
GROUP BY tenKhuvuc
HAVING COUNT (*) = 3;
--Câu 26--
SELECT tenPhong
FROM Phong
JOIN May ON May.MP = Phong.MP
JOIN Caidat ON Caidat.idMay = May.idMay
JOIN Phanmem ON Phanmem.idPM = Caidat.idPM
WHERE tenPM = 'Oracle 6'
GROUP BY tenPhong
HAVING COUNT (*) >= 1;
--Câu 27--
select m.tenMay
from May m
join Caidat cd on m.idMay = cd.idMay
where m.idMay!='p6' and cd.idPM in (
select idPM
from Caidat
where idMay ='p6'
);
--Câu 28--
select tenPM
from Phanmem
where (idloai='PCNT' and gia>Any(
select gia
from Phanmem
where idloai='UNIX')
);
--Câu 29--
select tenPM
from Phanmem
where (idloai='UNIX' and gia>ALL(
select gia
from Phanmem
where idloai='PCNT')
);
--Câu 30--
select idMay
from Caidat
where idMay!='p6' and idPM in (
select idPM
from Caidat
where idMay='p6'
);
--Câu 31--
select idMay
from caidat
where idPM in (
select idPM
from Caidat
where idMay='p2')
Group by idMay
Having count (*) = (
Select count (*)
from (
select idPM
from Caidat
where idMay = 'p2')
);

You might also like