Khoá học lập trình SQL [Video] Bài tập - Quản lý quán cafe - Lập trình SQL Server - MySQL

  • 5.0/5.0
  • 2k Đăng ký
  • Học lập trình
  • Tiếng việt

Thông tin khóa học



- Danh mục : category
	- id : int -> primary key -> identity (1,1)
	- name : nvarchar(50)
- Sản phẩm : product
	- id : int -> primary key -> identity (1,1)
	- title : nvarchar(50)
	- price : float
	- description: text -> giới thiệu đồ uống
	- id_category: int -> foreign key -> category (id)
- Nhân viên : staff
	- id : int -> primary key -> identity (1,1)
	- fullname : nvarchar(50)
	- address : nvarchar(150)
	- gender : nvarchar(15)
	- birthday : date
	- phone_number : nvarchar(20)

- Khách hàng: customer
	- id: int => primary key => identity (1,1)
	- fullname: nvarchar(50)
	- phone_number: nvarchar(20)
	- email: nvarchar(150)
	
- Quản lý đơn hàng :
	Khách hàng : tên, số điện thoại, email
		- cafe
		- sinh tố
		- nước ép cam

	Order
		id : int => primary key => identity (1,1) => mã đơn hàng
		customer_id: int => foreign key => customer (id)
		staff_id: int => foreign key => staff (id)
		price_total: float

	OrderDetail
		id: int => primary key => identity (1,1) => mã chi tiết đơn hàng
		order_id: int => foreign key => order (id)
		product_id: int => foreign key => product (id)
		price: float
		num: int
		price_total: float





-- Tao database : QuanLyCafe
create database QuanLyCafe
go

-- Kich hoat database : QuanLyCafe
use QuanLyCafe
go

-- Tao bang Category
create table Category (
	id int primary key identity(1,1),
	name nvarchar(50) not null
)
go

create table Product (
	id int primary key identity(1,1),
	title nvarchar(50) not null,
	description text,
	price float,
	category_id int references category(id)
)
go

create table Staff (
	id int primary key identity(1,1),
	fullname nvarchar(50) not null,
	address nvarchar(200),
	gender nvarchar(20),
	birthday date,
	phone_number nvarchar(20)
)
go

create table Customer (
	id int primary key identity(1,1),
	fullname nvarchar(50) not null,
	phone_number nvarchar(150),
	email nvarchar(50)
)
go

create table Orders (
	id int primary key identity(1,1),
	customer_id int references Customer (id),
	staff_id int references Staff (id),
	price_total float
)
go

alter table Orders
add created_at datetime

create table OrderDetail (
	id int primary key identity(1,1),
	product_id int references Product (id),
	price float,
	num int,
	price_total float,
	order_id int references Orders (id)
)
go

-- Nhap du lieu mau cho database
insert into Category (name)
values
('Cafe'),
('Nuoc Ep'),
('Sinh To')
go

select * from Category

insert into Product(title, price, category_id)
values
('Cafe Sua',32000, 1),
('Cafe Da', 29000, 1),
('Cafe Nong', 49000, 1),
('Nuoc Ep Oi', 59000, 2),
('Nuoc Ep Cam', 69000, 2)
go

insert into Staff(fullname, gender, birthday, phone_number, address)
values
('Tran Van A', 'Nam', '1999-02-06', '123456789', 'Ha Noi'),
('Tran Thi B', 'Nu', '1990-06-12', '1231321232', 'Ha Noi')
go

insert into Customer (fullname, email, phone_number)
values
('Nguyen Van A', 'a@gmail.com', '123'),
('Nguyen Van B', 'b@gmail.com', '123'),
('Nguyen Van C', 'c@gmail.com', '123'),
('Nguyen Van D', 'd@gmail.com', '123'),
('Nguyen Van E', 'e@gmail.com', '123')
go

insert into Orders (customer_id, staff_id, price_total)
values
(1, 1, 96000)
go
update Orders set created_at = '2020-08-20' where id = 1

insert into OrderDetail (order_id, product_id, price, num, price_total)
values
(1, 1, 32000, 3, 96000)


insert into Orders (customer_id, staff_id, price_total, created_at)
values
(1, 1, 133000, '2020-08-22')
go
update Orders set customer_id = 2 where id = 2

insert into OrderDetail (order_id, product_id, price, num, price_total)
values
(2, 1, 32000, 2, 64000),
(2, 5, 69000, 1, 69000)
go

-- Hiển thị danh sách loại đồ uống theo một danh mục -> yêu cầu viết truy vấn sql, tạo store (phần này làm 2 ý tách biết)
select * from Category
select * from Product

----- Hien thi : CategoryName, ProductName, Price
select Category.name CategoryName, Product.title ProductName, Product.price Price
from Category, Product
where Category.id = Product.category_id
	and Category.id = 1

create proc proc_xem_menu_theo_danh_muc
	@id int
as
begin
	select Category.name CategoryName, Product.title ProductName, Product.price Price
	from Category, Product
	where Category.id = Product.category_id
		and Category.id = @id
end

exec proc_xem_menu_theo_danh_muc 1

----- Hiển thị danh mục sản phẩm trong 1 đơn hàng -> yêu cầu viết truy vấn sql và tạo 1 store cho chức năng này
--------- OrderId, StaffName, CustomerName, ProductName, Price, Num, PriceTotal, OrderDate
--------- Orders, OrderDetail, Staff, Customer, Product
select Orders.id OrderId, Staff.fullname StaffName, Customer.fullname CustomerName, Product.title ProductName, OrderDetail.price Price, OrderDetail.num Num, Orders.created_at OrderDate
from Orders, OrderDetail, Staff, Customer, Product
where Orders.id = OrderDetail.order_id
	and Orders.customer_id = Customer.id
	and Orders.staff_id = Staff.id
	and OrderDetail.product_id = Product.id
	and Orders.id = 2

select * from Orders
select * from Customer

create proc proc_xem_don_hang
	@orderId int
as
begin
	select Orders.id OrderId, Staff.fullname StaffName, Customer.fullname CustomerName, Product.title ProductName, OrderDetail.price Price, OrderDetail.num Num, Orders.created_at OrderDate
	from Orders, OrderDetail, Staff, Customer, Product
	where Orders.id = OrderDetail.order_id
		and Orders.customer_id = Customer.id
		and Orders.staff_id = Staff.id
		and OrderDetail.product_id = Product.id
		and Orders.id = @orderId
end

exec proc_xem_don_hang 2

create proc proc_xem_don_hang_theo_ma_kh
	@customerId int
as
begin
	select Orders.id OrderId, Staff.fullname StaffName, Customer.fullname CustomerName, Product.title ProductName, OrderDetail.price Price, OrderDetail.num Num, Orders.created_at OrderDate
	from Orders, OrderDetail, Staff, Customer, Product
	where Orders.id = OrderDetail.order_id
		and Orders.customer_id = Customer.id
		and Orders.staff_id = Staff.id
		and OrderDetail.product_id = Product.id
		and Orders.customer_id = @customerId
end

exec proc_xem_don_hang_theo_ma_kh 2

---- Hiển thị doanh thu theo ngày bắt đầu và ngày kết thức -> yêu cầu viết theo store.
select Orders.id OrderId, Staff.fullname StaffName, Customer.fullname CustomerName, Product.title ProductName, OrderDetail.price Price, OrderDetail.num Num, Orders.created_at OrderDate
	from Orders, OrderDetail, Staff, Customer, Product
	where Orders.id = OrderDetail.order_id
		and Orders.customer_id = Customer.id
		and Orders.staff_id = Staff.id
		and OrderDetail.product_id = Product.id
		and Orders.created_at >= '2020-08-18'
		and Orders.created_at <= '2020-08-21'

select sum(price_total) 'Tong Doanh Thu'
from Orders
where Orders.created_at >= '2020-08-18'
	and Orders.created_at <= '2020-08-22'

create proc proc_doanh_thu
	@startDate date,
	@endDate date
as
begin
	select sum(price_total) 'Tong Doanh Thu'
	from Orders
	where Orders.created_at >= @startDate
		and Orders.created_at <= @endDate
end

exec proc_doanh_thu '2020-08-18', '2020-08-23'


Bài tập - Quản lý quán cafe - Lập trình SQL Server - MySQL


Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó

Chương trình

Video Hướng dẫn cách xác định kiểu dữ liệu, primary key, foreign key trong SQL - My SQL - SQL Server
Bài tập - Thiết kế CSDL - Tạo bảng, thêm dữ liêu, hiển thị dữ liệu - Lập trình SQL Server
Video Hướng dẫn thao tác nhiểu bảng - select - multi table - join, inner join trong SQL Server
Thiết kế database - bãi đỗ xe - Lập trình SQL Server
Video Hướng dẫn phân tích CSDL - phân tích bảng, column trong bản - Học lập trình SQL, SQL Server
Video Hướng dẫn tìm hiểu create, alter , insert table và bản chất primary key, foreign key - SQL Server
Video Hướng dẫn tìm hiểu select, and, in, like, not in,group by .. having, order by asc, desc - SQL Server
Thiết kế hệ quản trị CSDL - Quản lý sinh viên (create, alter, update, insert, select) - Lập trình SQL Server
Video Quản lý sinh viên (create, alter, update, insert, select) - Lập trình SQL Server
Thiết kế CSDL quản lý sinh viên - lập trình sql server
SQL - Thiết kế CSDL quản lý bán hàng - Lập trình SQL Server
Thiết kế CSDL quản lý bán hàng - create - alter - insert - update - delete trong CSDL - Học lập trình SQL Server
Quản lý khách sạn - nâng cao - Lập trình Sql Server

Video Hướng dẫn tìm hiểu view trong SQL Server
Bài Giảng: Hướng dẫn tìm hiểu view + proc trong SQL - Lập trình SQL Server
Bài tập - Thiết kế CSDL - sử dụng trong giải đấu bóng đá FIFA - champions league - world cup - Lập trình SQL Server

Video Hướng dẫn tìm hiểu proc procedure trong SQL Server - Lập trình SQL Server, MySQL
Bài tập - Quản lý bãi đỗ xe - Lập trình SQL Server
Bài tập - Xây dự hệ thống đưa đón học sinh bằng xe bus của Trường Học - Lập trình SQL Server
Bài Giảng: Xây dự hệ thống đưa đón học sinh bằng xe bus của Trường Học - Lập trình SQL Server
Bài tập - Thiết kế CSDL quản lý sở thú - SQL Server
Bài Giảng: Bài tập - Thiết kế CSDL quản lý sở thú - SQL Server
Bài tập - Chương trình quản lý bán hàng - Lập trình SQL Server
Xây dựng CSDL quản lý điểm danh Trường Học - Lập trình SQL Server/MySQL
Video Xây dựng CSDL quản lý điểm danh aptech - Lập trình SQL Server/MySQL
Bài tập - Quản lý quán cafe - Lập trình SQL Server - MySQL
Video Bài tập - Quản lý quán cafe - Lập trình SQL Server - MySQL

Video Học Trigger qua ví dụ - quản lý nhà trên phố - Lập trình SQL Server
Video Hướng dẫn học trigger qua bài quản lý điểm danh Aptech - Lập trình SQL Server
Bài tập - Quản lý nhân khẩu - Lập trình SQL Server - MySQL
Video Bài tập - Quản lý nhân khẩu - Lập trình SQL Server - MySQL

[Examination] Bài Thi Thực Hành SQL Server
[Examination] Quản lý sản phẩm - Lập trình SQL Server
[Examination] Hệ thống quản lý sinh viên - SQL Server
Bài Giảng: Hệ thống quản lý sinh viên - Lập trình SQL Server
Nguyễn Văn An
Nguyễn Văn An
2026-06-22 12:32:24
Khóa học cực kỳ chất lượng, giảng viên hướng dẫn rất chi tiết và dễ hiểu. Mình đã áp dụng được ngay vào công việc thực tế.
Trần Thị Bích
Trần Thị Bích
2026-06-19 12:32:24
Nội dung bài giảng được sắp xếp logic, đi từ cơ bản đến nâng cao. Rất phù hợp cho người mới bắt đầu.
Lê Hoàng Hải
Lê Hoàng Hải
2026-06-17 12:32:24
Khóa học hay, tuy nhiên phần bài tập thực hành hơi khó một chút. Cần phải xem lại video vài lần mới làm được.
Phạm Minh Tuấn
Phạm Minh Tuấn
2026-06-10 12:32:24
Tuyệt vời! Đây là khóa học tốt nhất mình từng tham gia. Support nhiệt tình, giải đáp thắc mắc rất nhanh.

Đánh giá

B1. B1. Tạo tài khoản -> Sử dụng để học online
B2. Đăng ký học
B3. Hoàn thành mua khoá học
B4. Thanh toán theo hướng dẫn
B5. Đợi chúng tôi kiểm tra thông tin và thêm bạn vào lớp học

Chào mừng các anh chị và các bạn gia nhập đội ngũ Giảng viên QViet. Anh chị vui lòng đăng ký theo hướng dẫn sau:
Bước 1: Truy cập website https://gozic.vn/teacher/form
Bước 2: Điền thông tin theo yêu cầu. Để bản đăng ký được duyệt nhanh nhất, anh chị hãy điền đủ thông tin nhé.
Bước 3: Click vào "đăng ký ngay" để hoàn thành
Lưu ý:
Link video bài giảng mẫu: Video bài giảng mẫu là căn cứ để Trắc Nghiệm Việt duyệt về hình thức và chất lượng giảng dạy. Vì vậy anh chị hãy điền link này để đăng ký được duyệt nhanh nhất nhé.
Anh chị cũng nên mô tả kỹ về kinh nghiệm giảng dạy để Trắc Nghiệm Việt đánh giá nhé.
Chúc các anh chị và các bạn thành công, sớm gia nhập đội ngũ giảng viên Trắc Nghiệm Việt!
×