Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Bài 1:

1. Select * from SINHVIEN Where diachi like ‘Đà Nẵng’;


2. Select * from SINHVIEN Where hovaten like ‘Nguyễn%’;
3. Select * from SINHVIEN Where malop = ‘ML001’ and diemthi > 7;
4. Select * from SINHVIEN Where month (ngaysinh) = 8 or diachi like ‘Hà Nội’;
5. Select * from SINHVIEN order by diemthi asc;
6. Select top 5 diemthi from SINHVIEN order by desc;

Bài 2:
1. Select count (*) from TABLE Where Address like ‘%Hà Nội%’;
2. Select MAX (Tonghoadon) from TABLE;
Select MIN (Tonghoadon) from TABLE;
Select AVG (Tonghoadon) from TABLE;
3. Select TOP 1 Tonghoadon from TABLE Where month (NgayHD) =7 and year (NgayHD) = 2022;
4. Select * from TABLE Where Phone like ‘09%’
5. Select * from TABLE Where Phone like ‘%678’
6. Select * from TABLE order by SoLuongSP asc;
7. Select distinct CustomerName from TABLE;
8. Select * from TABLE Where Address like ‘%Đà Nẵng%’ and Tonghoadon > 300000;
9. Select sum(SoLuongSP) from TABLE;
10. Select count(OrderID) from TABLE Where NgayHD in (month (NgayHD) = 6 and year (NgayHD) =
2022);
11. Select count (CustomerName like ‘%Nguyen Thi Phuong%’) from TABLE;

Bài 3:

1. Select N.MaNhaCC, N.TenNhaCC, N.DiaChi, N.SoDT, N.MaSoThue from NHACUNGCAP N


Join DANGKYCUNGCAP DK on N.MaNhaCC = DK.MaNhaCC
Join MUCPHI M on DK.MaMP = M.MaMP
Join DONGXE D on DK.DongXe = D.DongXe
Where (D.HangXe like ‘%Toyota%’ and M.DonGia = 15.000) or (D.HangXe like ‘%KIA%’ and
M.DonGia = 20.000);
2. Select DK.MaDKCC, DK.MaNhaCC, DK.MaLoaiDV, DK.DongXe, DK.MaMP,
DK.NgayBatDauCungCap, DK.NgayKetThucCungCap, DK.SoLuongXeDangKy from
DANGKYCUNGCAP DK
Join DONGXE D on DK.DongXe = D.DongXe
Where D.SoChoNgoi >5;
3. Select L.MaLoaiDV, L.TenLoaiDV from LOAIDICHVU L
Join DANGKYCUNGCAP DK on L.MaLoaiDV = DK.MaLoaiDV
Join MUCPHI M on DK.MaMP = M.MaMP
Join DONGXE D on DK.DongXe = D.DongXe
Where M.DonGia = 15.000 and D.HangXe like ‘%Toyota%’;
4. Select L.MaLoaiDV, L.TenLoaiDV from LOAIDICHVU
Join DANGKYCUNGCAP DK on L.MaLoaiDV = DK.MaLoaiDV
Join DONGXE D on DK.DongXe = D.DongXe
Where D.SoChoNgoi = 5;
5. Select count(DK.MaNhaCC) from DANGKYCUNGCAP DK
Join NHACUNGCAP N on N.MaNhaCC = DK.maNhaCC
Where N.TenNhaCC like ‘%AMA%’;
6. Select count (DK.DongXe) from DANGKYCUNGCAP DK
Join DONGXE D on DK.DongXe = D.DongXe
Where D.HangXe like ‘%Toyota%’;
7. Select DK.MaDKCC, DK.MaNhaCC, DK.MaLoaiDV, DK.DongXe, DK.MaMP,
DK.NgayBatDauCungCap, DK.NgayKetThucCungCap, DK.SoLuongXeDangKy from
DANGKYCUNGCAP DK
Join NHACUNGCAP N on DK.MaNhaCC = N.MaNhaCC
Where N.tenNhaCC like ‘%Đông Du%’
Order by DK.SoLuongXeDangKy desc;
8. Select DK.MaDKCC, DK.MaNhaCC, DK.MaLoaiDV, DK.DongXe, DK.MaMP,
DK.NgayBatDauCungCap, DK.NgayKetThucCungCap, DK.SoLuongXeDangKy from
DANGKYCUNGCAP DK
Join MUCPHI M on DK.MaMP = M.MaMP
Order by M.DonGia asc;
9. Select M.MaMP, M.DonGia, M.MoTa from MUCPHI M
Join DANGKYCUNGCAP DK on M.MaMP = DK.maMP
Join DONGXE D on DK.DongXe = D.DongXe
Where D.HangXe like ‘%Huyndai%’;
10. Select sum(DK.SoLuongXeDangKy) from DANGKYCUNGCAP DK
Join NHACUNGCAP N on DK.MaNhaCC = N.MaNhaCC
Where N.DiaChi like ‘%Hải Châu%’;
11. Select Max(DK.NgayKetThucCungCap – DK.NgayBatDauCungCap) from DANGKYCUNGCAP DK
Join LOAIDICHVU L on DK.MaLoaiDV = L.MaLoaiDV
Where L.TenLoaiDV like ‘%Dịch vụ xe Bus%’;
12. Select Min (DK.SoLuongXeDangKy) from DANGKYCUNGCAP DK
Join DONGXE D on DK.DongXe = D.DongXe
Where D.HangXe like ‘%KIA%’;
13. Select D.DongXe, D.HangXe, D.SoChoNgoi from DONGXE D
Join DANGKYCUNGCAP DK on D.DongXe = DK.DongXe
Join MUCPHI M on DK.MaMP = M.MaMP
Where M.DonGia between 15.000 and 20.000 or DK.SoLuongXeDangKy >=7;
14. Select N.TenNhaCC, DK.NgayBatDauCungCap, DK.NgayKetThucCungCap, DK.SoLuongXeDangKy,
L.TenLoaiDV, D.HangXe, D.SoChoNgoi, M.DonGia from NHACUNGCAP N
Join DANGKYCUNGCAP DK on N.MaNhaCC = DK.MaNhaCC
Join LOAIDICHVU L on DK.MaLoaiDV = L.MaLoaiDV
Join MUCPHI M on DK.MaMP = M.MaMP
Join DONGXE D on DK.DongXe = D.DongXe;
Where DK.NgayBatDauCungCap from 20/95/2015 to Now();
15. Select D.DongXe, DK.NgayBatDauCungCap, DK.NgayKetThucCungCap, DK.SoLuongXeDangKy
from DANGKYCUNGCAP DK
Join DONGXE D on D.DongXe = DK.DongXe
Join MUCPHI M on DK.MaMP = M.MaMP
Where M.DonGia = 10.000;

Bài 4:

1. Select C.CustomerName, count(C.CustomerID) from Order O


Join Customer C on C.CustomerID = O.CustomerID
group by C.CustomerName;
2. Select P.ProductName, count(O.OrderID) from Order O
join Product P on O.ProductID = P.ProductID
group by ProductName;
3. Select P.ProductName, sum(O.Quantity) from Order O
join Product P on O.ProductID = P.ProductID
group by P.ProductName;
4. Select C.CustomerName, sum(O.Quatity * P.UnitPrice) from Order O
Join Product P on O.ProductID = P.ProductID
group by C.CustomerName;
order by desc;
5. Select C.CustomerName, sum(O.Quantity*P.UnitPrice) from Order O
Join Product P on O.PrductID = P.ProductID
Join Customer C on O.CustomerID = C.CustomerID
Where year(OrderDate) = 2022
Group By month(OrderDate);
6. Select TOP 1 count(O.OrderID), CustomerName from Customer C
Join Order O on C.CustomerID = O.CustomerID
Group by C.CustomerName;
7. Select TOP 1 sum(O.Quantity * P.UnitPrice), C.CustomerName from Order O
Join Product P on O.ProductID = P.ProductID
Join Customer C on O.CustomerID = C.CustomerID
Group by C.CustomerName;

Bài 5:

1. Select C.CustomerName, count(O.OrderID) from Customer C


Join Order O on C.CustomerID = O.CustomerID
Where count(O.OrderID) > 1
Group by C.CustomerName;
2. Select P.ProductName, O.Quantity from Order O
join Product P on O.ProductID = P.ProductID
where O.Quantity >5
group by ProductName;
3. Select C.CustomerName , sum(O.Quantity * P.UnitPrice) from Order O
Join Product P on O.ProductID = P.ProductID
Join Customer C on O.CustomerID = C.CustomerID
Where sum(O.Quantity * P.UnitPrice) > 25.000
Group by C.CustomerName;
4. Select month(O.OrderDate), sum(O.Quantity*P.UnitPrice) from Order O
Join Product P on O.ProductID = P.ProductID
Join Customer C on O.CustomerID = C.CustomerID
Where sum(O.Quantity*P.UnitPrice) > 500000 and year(O.OrderDate) = 2022
Group By month(O.OrderDate);
5. Select O.OrderID, C.Address from Order O
Join Customer C on O.CustomerID = C.CustomerID
Where C.Address like ‘%Đà Nẵng%’;
6. Select O.OrderID, P.UnitPrice from Order O
Join Product P on O.ProductID = P.ProductID
Where P.UnitPrice < 500000;
7. Select O.OrderID, P.UnitPrice, C.Address from Order O
Join Product P on O.ProductID = P.ProductID
Join Customer C on O.CustomerID = C.CustomerID
Where P.UnitPrice > 100000 and C.Address like ‘%Hà Nội%’;

You might also like