Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Table of Contents

I. Abstract 2
II. Introduction 2
1. About the organization: 2
2. Requirement Analysis 3
3. Business Narrative 6
Analyzing and designing the database 7
1. Explanation of E-R Diagram 7
2. Relational schema and normalization 10
III. Some useful reports and information 18
III. Conclusion 34
I. Abstract
Pharmacy Management System is a Database Management System for managing both
billing and drug inventory which helps in maintaining the records of medicines,
employees, and customers and also reduces the work of searching the medicine. The
main aim of this system is to apply technology to support the pharmacists and the stores
to reduce the human effort in searching and automation the billing. This system can be
used by any store to automate the process of manually maintaining pharmacy-related
records. The system uses the insurance of patients and can also notify employees of
events performed in the pharmacy.

II. Introduction
1. About the organization:
- DB Pharmacy was established in 2022. DB is a GPP standard pharmacy with
modern and advanced facilities, full of necessary equipment and facilities for drug
preservation: self-recorded thermometers, air conditioners, refrigerators, and
operating dehumidifiers 24/24 to ensure drug storage conditions as required. In
addition, the pharmacy also meets the standards of personnel. In charge of the
pharmacy is a university pharmacist with a certificate of pharmacy practice with
many years of experience working in a famous hospital. The DB also meets the
standard of performance: accurate and secure record keeping and record keeping.
Buy drugs and control the quality of drugs fully.
- Mission: To help our patieConfidentialitynts get better and live healthier lives, we
provide the best quality medical supplies and medicines along with expert advice
on the safest and most effective use of medicines for our patients.
- Vision: To become the nation’s leading pharmacy by providing a healthy and
quality life for patients.
- Our values:
+ Customer focus
+ Competency
+ Compassion
+ Confidentiality
+ Community minded
+ Continuous provided
- Project main purpose: We create a pharmacy management system with the main
purpose of managing the pharmacy in the most effective way. This system
includes all information about prescriptions, sales, inventory quantities to ensure
customer orders as well as order status and daily purchases. In addition, the system
also manages customers. The necessary information to track customer orders
during purchase or delivery. Avoid giving the wrong order or selling at the wrong
price, or quantity deviation in stock.
2. Requirement Analysis
Methods for investigating business rules:
The information used in this report is gathered from the following sources
Website
The database is designed mainly based on the information referenced from Pharmacy.
Documents
Before customers buy and pay for products, they must provide their name, phone number
and payment method. We use these references to create our tables.
Observation
The experience of selling offline at Pharmacy drug stores helps us partially design this
database.

The pharmacy requirements to be achieved based on our research and understanding are:
Customer
When patients arrive at the store, we will obtain their health ID and identify them based
on their health ID. If they are a new patient, we will collect data such as name, date of
birth, address, health ID, phone number, gender, and insurance Id. The patient will have a
prescription using which order will be created and the patient will then pay the bill
Employee
An employee has an employee id, role, license, phone no, salary and name employee can
be a cashier or pharmacist. If an employee is preparing the order then his/her ID will be
used in the order. The employee authorizes the disposal ines. Employees will be notified
of orders and disposals.
An employee has to have one of the following roles:
1. Pharmacist
2. Pharmacy technician
3. Pharmacy assistant
4. Pharmacy clerk
5. Pharmacy Dispenser
6. Nuclear pharmacist
7. Chemotherapy pharmacist
Prescription
When customers come, they will be asked to give prescriptions stamped and signed by
the doctor who gives those drugs, then our pharmacy will take the correct medicine and
dosage as the doctor has prescribed. The prescription contains the customer's number and
the id of the doctor prescribing the drug. Absolutely do not take more than the prescribed
amount.
Prescribed Drug
Every prescription contains prescribed drugs and their information. The drug’s, name,
quantity and refill limit must be stated on the prescription,
Bill
After the customer confirms the drug and quantity to go to the payment step, the bill will
be printed with the information of the drug price, quantity and information of the buyer.
Customers are kindly requested to keep the receipt in case of any circumstances that can
be brought to exchange with the pharmacy.
Notifications
The system will send a notification to the pharmacist:
-Stock for medicine is low (less than 100 tablets)
-Some medicine will expire in the next 60 days
-Drugs are marked for disposal
-Drugs are successfully disposed
Medicine (inventory)
It is beneficial to store an updated inventory for record-keeping and to know when we are
short of stock. The inventory will contain all the information on the medicines in the
pharmacy the name of the medicine, the type of medicine, the manufacturer, the expiry
date, the price, the quantity in stock, and the batch number. When a medicine approaches
its expiration date, it will be disposed of.
Insurance
In case the patient has health insurance, the pharmacy will note that insurance ID
including company name, start-end date, patient name, and insurance percentage. Based
on that, the pharmacy will calculate the amount to be paid by the insurance company and
the patient.
Order
The prescription will generate an order and each order will be identified by a unique
order ID. This includes the drug ID, employee ID, order date, name of the drug, quantity,
and batch number. This is the information required to place an order.

3. Business Narrative
3.1 Business Rules
Patients only buy drugs according to the prescription that the doctor has prescribed or
according to the instructions and advice of the pharmacist at the pharmacy. Only a certain
amount of medicine can be purchased, some prescription drugs must be purchased at the
hospital.
3.2. Business Narrative
● Each DB customer will have a unique number and their personal information is
stored and secured.
● Each drug contains a fixed amount of data with Dru_Code as the identifier.
● An employee can receive many notifications, a notification can be sent to many
different employees, here is a many-to-many relationship.
● Each patient can have different prescriptions, while each prescription belongs only
to one patient.
● Each prescription is written by a doctor and a doctor can write many prescriptions
for different patients.
● An order can contain one or more different drugs, it is a one-to-many relationship.
But an order has only one invoice. So, the relationship of the order and the invoice
is one-to-one.
● A patient can have many different orders, so the relation between them is
one-to-many.
● Although each drug has a different unique ID in the reserve, but it can be in many
prescriptions.
● An employee can throw away many drugs, many employees can also throw many
drugs, so the relationship here is many to many.
III. Analyzing and designing the database

More quality diagram viewing: HERE

1. Explanation of E-R Diagram


Patient Holds Prescription

A patient can have many prescriptions. However, a prescription can only belong to a
single patient. Thus the relationship between Patient and Prescription entity is one to
many. Each patient will have a prescription and each prescription belongs to a patient so
the participation is Total of both sides.

Insurance insures Patient

A patient can claim one insurance and insurance can only insure one patient. Thus the
relationship between Insurance and Patient is one-to-one. A patient may not have
insurance so patient participation in insurance is partial. However, each insurance belongs
to a patient so insurance participation is total in insurance.

Patient Pays Bill

A patient can pay several bills, but a bill will only be paid by a single patient. Thus, the
relationship between Patient and Bill is one to many. Each patient pays for his bill and
each bill is paid by a patient so the participation is Total of both sides.

Prescription consists Of Prescribed Drug

A prescription may have several prescribed drugs but a drug with an order id will be on
only one prescription so the relationship between prescription and prescribed drug is one
to many. Each prescription will have a prescribed drug on it and each prescribed drug will
be on a prescription, so the participation is Total of both sides.

Prescription Uses Order

A prescription can generate multiple orders but an order will only be generated using
single prescription. Thus, the relationship between Prescription and order is one to many.
Each prescription will be used for some order and each order will be generated using a
prescription. So the participation is Total of both sides.

Order makes Bill

An order can only generate one bill and a bill be generated for only one order so the
relationship between the order and bill is one-to-one. Each order will generate a bill and
each bill will be generated for an order so the participation is Total of both sides.

Order Contains Ordered Drugs

An order can contain multiple ordered drugs but an ordered drug with its order ID and
drug name will be only be in an order. Thus the relationship between order and ordered
drugs is one to many. Each order will contain some drugs and each ordered drugs will be
in some order. So the participation is Total of both sides.

Employee Prepares Order


An employee can prepare many orders but an order will be prepared by only one
employee. Thus, the relationship between order and ordered drugs is one to many. Each
order will be prepared by some employee but not every employee prepares order so the
order participation is Total in prepares and the employee participation is partial in
prepares.

Ordered Drugs Fetched Medicine

A medicine will be fetched by an ordered drug and an ordered drug will fetch only one
medicine. So the relationship between ordered drugs and medicine is one to one. Each
ordered drug will fetch some medicine but every medicine will not be fetched so the
participation of ordered drugs in fetched is Total but the participation of medicine in
fetched is partial.

Medicine Disposes Disposal

Disposal is weak entity and is dependent on Medicine so the relationship between them
disposed of is weak relationship. Disposal uses foreign key drug name and batches no as
its primary key. Every disposed of drug is from medicine so the participation of disposal
is total in disposes of. Not every medicine is disposed so the participation of medicine in
disposes is partial.

Employee Authorizes Disposal

An employee can authorize many disposals and disposal can be authorized by many
employees. So the relationship between them is many to many. Not every employee
authorizes disposal so the participation of employees in authorizes is partial. Each
disposal is authorized by an employee so the participation of disposal in authorization is
Total.

Employee is Notified Notification

An employee can receive many notifications and a notification can be sent to many
employees so the relationship between them is many to many. Not every employee
receives a notification, but every notification is sent to some employees so the
participation of employees in isNotified is partial and the participation of notification in
isNotified is Total.

2. Relations and Normalization

Relations
The final relations are listed below:
Customer
Custome First Last Phone Gender Address Date of Insuran
r ID Name Name Birth ce ID
Primary Key: Customer ID
Foreign Key: Customer(Insurance ID) 🡪 Insurance(Insurance ID)
Insurance
Insurance Company Start End Co
ID Name Date Date Insurance

Primary Key: Insurance ID


Employee
ID Customer License First Last Start End Role
ID Name Name Date Date

Salary Phone Date of Birth


Number
Primary Key: ID

Prescription
Prescripti Custome Doctor Prescription
on ID r ID ID Date
Primary Key: Prescription ID
Foreign Key: Prescription(Customer ID) 🡪 Customer(Customer ID)

Prescribed Drugs
Prescripti Drug Prescribed Refill
on ID Name Quantity Limit
Primary Key: Prescription ID, Drug Name
Foreign Key: Prescribed Drugs(Prescription ID) 🡪 Prescription(Prescription ID)

Order
Order ID Prescripti EmployeeI Order
on ID D Date

Primary Key: Order ID


Foreign Key: Order(Prescription ID) 🡪 Prescription(Prescription ID),
Order(Employee ID) 🡪 Employee(ID)

Ordered Drugs
Order Drug Batch Quantity Price
ID Name Number
Primary Key: Order ID, Drug Name, Batch Number
Foreign Key: Ordered Drugs(Order ID) 🡪 Order(Order ID), Ordered
Drugs(Drug Name, Batch Number) 🡪 Medicine(Drug Name, Batch
Number)

Bill
Order ID CustomerCu Total Customer Insurance
stomer ID Amount Payment Payment

Primary Key: Order ID, Customer Customer ID


Foreign Key: Bill(Order ID) 🡪 Order(Order ID), Bill(Customer Customer ID) 🡪
Customer(Customer ID)

Medicine
Drug Batch Medicine Manufacture Quantit Expiry Price
Name Number Type r y Date
Primary Key: Drug Name,
Batch Number

Disposed Drugs
Drug Batch Quantit Compan
Name Number y y
Primary Key: Drug Name, Batch Number
Foreign Key: Disposed Drugs(Drug Name, Batch Number) 🡪
Medicine(Drug Name, Batch Number)

Notification
ID Message Type
Primary Key: ID

Employee_Disposed Drugs
Emplo Drug Batch Disposal
yee ID Name Number Date
Primary Key: Employee ID, Drug Name, Batch Number, Disposal Date
Foreign Key: Employee_Disposed Drugs(Employee ID) 🡪 Employee
(Employee ID), Employee_Disposed Drugs(Drug Name, Batch Number)
🡪 Disposed Drugs(Drug Name, Batch Number)

Employee Notification
Emplo Notificat
yee ID ion ID
Primary: Employee ID, Notification ID
Foregin Key: Employee Notification(Employee ID) 🡪
Employee(ID), Employee Notification(Notification ID) 🡪
Notification(Notification ID)

Normalization
The following dependencies exist in our schema:

1. Insurance(Insurance ID, Company Name, Start Date, End


Date, Co-Insurance) Insurance ID 🡪 Company Name, Start
Date, End Date, Co-Insurance

2. Customer(Customer ID, First Name, Last Name, Phone, Gender,


Address, Dateof Birth, Insurance ID) Customer ID 🡪 First Name, Last
Name, Phone, Gender, Address, Date of Birth, Insurance ID

3. Prescription(Prescription ID, Customer ID, Doctor ID, Prescribed Date)


Prescription ID 🡪 Customer ID, Doctor ID, Prescribed Date

4. Prescribed_Drugs(Prescription ID, Drug Name, Prescribed


Quantity, Refill Limit) Prescription ID, Drug Name 🡪
Prescribed Quantity, Refill Limit

5. Order(Order ID, Prescription ID, Employee ID, Order Date)


Order ID 🡪 Prescriptio ID, Employee ID, Order Date

6. Ordered Drugs(Order ID, Dug Name, Batch Number,


Ordered Quantity, Price) Order ID, Dug Name, Batch
Number 🡪 Ordered Quantity, Price

7. Bill(Order ID, CustomerCustomer ID, Total Amount, Customer


Payment, Insurance Payment) Order ID, CustomerCustomer ID 🡪
Total Amount, Customer Payment, Insurance Payment

8. Employee(Employee ID, Customer ID, First Name, Last Name, Start


Date, End Date, Role, Salary, Phone Number, Date of Birth)
Employee ID 🡪 Customer ID, First Name, Last Name, Start Date, End Date,
Role, Salary, Phone Number, Date of Birth

9. Employee_Notification(Employee ID, Notification ID)


All Keys.

10. Notification(Notification ID, Type, Message)


Notification ID 🡪 Type, Message

11. Employee_Disposed_Drugs(Employee ID, Drug Name, Batch


Number, Disposal Date) All Keys.
12. Disposed Drugs(Drug Name, Batch Number, Quantity, Company)
Drug Name, Batch Number 🡪 Quantity, Company

13. Medicine(Drug Name, Batch Number, Medicine Type, Manufacturer,


Stock Quantity, Expiry Date, Price)
Drug Name, Batch Number 🡪 Medicine Type, Manufacturer, Stock
Quantity, Expiry Date, Price None of the above dependencies violate 3NF
rules, so above relations are in 3NF.

III. SOME USEFUL REPORTS AND INFORMATION

1. TUẤN THÀNH PART


--1. Get the information to view employee information (name, id, role) and customer info
and prescription id (from Order table) ?

SELECT Customer.order_id, Customer.customer_id, Customer.fullname,


Customer.insurance_id, Employee.Employee_ID, Employee.Full_name, Employee.role,
"Order".Prescription_ID
FROM Customer
INNER JOIN "Order"
ON customer.order_id = "Order".order_id
INNER JOIN Employee
ON "Order".employee_id = Employee.employee_id
ORDER BY Order_id ASC;

--2. Count the number of customer live in Thanh Xuan District


SELECT Customer.address, COUNT(*) AS NUMBEROFCUSTOMER
FROM CUSTOMER
INNER JOIN "ORDER"
ON Customer.order_id = "Order".order_id
GROUP BY Customer.address
HAVING Customer.address = 'Thanh Xuân'
ORDER BY Customer.address DESC;

--3. Find the customer with the last name Nguyễn and sorts by ascending
select *from Customer
where fullname like N'Nguyễn%'
ORDER BY fullname ASC;

--4. Update medicine name (TRANSACTION)


update MEDICINE
set Manufacturer = 'DOMESCO Medical Import Export Joint Stock Corporation'
WHERE drug_name = 'Streptokinase'
commit
SELECT * from Medicine

--5/ Find Phamacist who have salary > $1000


SELECT *
FROM EMPLOYEE
WHERE role = 'Pharmacist' and
salary >= $1000

--6/ View the total amount of each customer (VIEW)


CREATE VIEW TotalCost AS
SELECT Customer.order_id, Customer.customer_id, Customer.fullname,
Customer.insurance_id, Bill.total_amount , bill.insurance_payment ,
bill.customer_payment
FROM CUSTOMER
INNER JOIN BILL
ON customer.order_id = Bill.order_id

SELECT * FROM TotalCost;

--7/ Retrieve the information when customer payment is between $10 and $40.
CREATE PROCEDURE ListBill_byprice @minprice int, @maxprice int
AS
BEGIN
SELECT order_id, customer_payment
FROM Bill WHERE customer_payment between @minprice and @maxprice
END

DECLARE @price int;


EXECUTE @price = ListBill_byprice $10, $40;
PRINT @price;
drop PROCEDURE ListBill_byprice
--8/ Create trigger that employee cannot change the order id
CREATE TRIGGER trigger_salary
ON Employee
FOR UPDATE
AS
BEGIN
IF UPDATE(salary)
BEGIN
PRINT 'Cannot modify the salary'
ROLLBACK TRANSACTION
END
END
--test
UPDATE Employee
set salary = 10000
where Employee_ID = 'E102'

drop trigger trigger_salary


select *from Employee;

--9/ --Write a trigger so that every time you delete the prescription id in the prescription
table,
--it will automatically delete the corresponding lines in the Bill table
create trigger delete_Prescription_ID
on Prescription
for DELETE
AS
BEGIN
delete from PRESCRIBED_DRUGS
where Prescription_ID in (
select Prescription_ID
from deleted)
END

drop trigger delete_Prescription_ID


--test
delete from Prescription where Prescription_ID = 'P102'

--10/ Find the order with the Expiry Date < 2023-12-12 and make disposal notification
SELECT drug_name , batch_number, Manufacturer, expiry_date
FROM Medicine
WHERE expiry_date < '2023-12-12'
ORDER BY expiry_date ASC;

---B101
SELECT Order_ID
FROM ORDERED_DRUGS
WHERE batch_number = 'B101'
--O110
INSERT INTO Notification (Notification_ID , Message , Action)
VALUES (value1, value2, value3, ...);

CREATE TRIGGER Update prize


ON
FOR Ordered_Drugs
AS
BEGIN
IF UPDATE(Total)
BEGIN
PRINT 'Cannot modify the salary'
ROLLBACK TRANSACTION
END
END

UPDATE Employee
set salary = 10000
where Employee_ID = 'E102'

--11/ When updating the salary of Employee, check that there is no higher salary with the
same role
CREATE TRIGGER LowerSalaryCheck
UPDATE salary
ON Employee
REFERENCING OLD ROW AS OldTuple
NEW ROW AS NewTuple
FOR EACH ROW
WHEN(NOT(NewTuple.salary <= ALL(SELECT salary FROM Employee WHERE
License = NewTuple.License)))
BEGIN
DELETE FROM Employee
WHERE (Employee_ID, License, Full_name, role , salary, phone_number, date_of_birth
) = NewTuple;
INSERT INTO Employee VALUES(OldTuple.Employee_ID, OldTuple.License,
OldTuple.Full_name,OldTuple.role, OldTuple.phone_number, OldTuple.date_of_birth);
END;

--12/ When inserting a new order, check that the order id exists in Customer
SELECT Order_ID
FROM Customer
WHERE EXISTS
(SELECT order_id FROM Prescription WHERE order_id = 'O103');

--9/ Which role has the highest salary?


⇒ Pharmacist and Nuclear Pharmacist (=$2500)

10/ Count the number of each address and visual it as a treemap diagram
2. LÂM TƯỜNG PART
–1. Get the information to view medicine information (from medicine table) and disposed
drugs ?

SELECT Medicine.drug_name, Medicine.batch_number, Medicine.MedicineType ,


Medicine.Manufacturer , Medicine.stock_quantity , Medicine.expiry_date,
Medicine.price, Disposed_drugs.Drug_name, Disposed_drugs.Batch_number,
Disposed_drugs.quantity
FROM Medicine
INNER JOIN Disposed_drugs
ON Medicine.batch_number = Disposed_drugs.batch_number
ORDER BY stock_quantity ASC;

--2. Count the number of liquid type medicine


SELECT Medicine.medicine_type, COUNT(*) AS NUMBEROFLIQUIDTYPE
FROM Medicine
INNER JOIN Disposed_drug
ON Medicine.Drug_name = Disposed_drug.batch_number
GROUP BY Medicine.medicine_type
HAVING Medicine.medicine_type = 'Liquid'
ORDER BY Medicine.medicine_type DESC;

--3. Find the manufacturer of drug are from Traphaco Joint Stock Company and sorts by
ascending
select *from Medicine
where Manufacturer like N'Traphaco Joint Stock Company%'
ORDER BY Manufacturer ASC;
Send Notifications

--4. Retrieve the information when customer payment is between $30 and $100.
CREATE PROCEDURE ListBill_byprice @minprice int, @maxprice int
AS
BEGIN
SELECT order_id, customer_payment
FROM Bill WHERE customer_payment between @minprice and @maxprice
END

DECLARE @price int;


EXECUTE @price = ListBill_byprice $30, $100;
PRINT @price;

–5.-- Find Phamacist who have salary < $1000


SELECT *
FROM EMPLOYEE
WHERE role = 'Pharmacist' and
salary <= $1000

–6. Find the order with the Expiry Date < 2023-12-20 and make disposal notification
SELECT drug_name , batch_number, Manufacturer, expiry_date
FROM Medicine
WHERE expiry_date < '2023-12-20'
ORDER BY expiry_date ASC;
---B101
SELECT Order_ID
FROM ORDERED_DRUGS
WHERE batch_number = 'B101'

–7. Count the number of Drug with Expiry Date between December 11th and December
31st
SELECT Expiry_Date, COUNT(*) AS NumberOfExpiryDatedDrug
FROM Medicine
WHERE Expiry_Date
BETWEEN ('2023-12-11') AND ('2023-12-31')
GROUP BY Expiry_Date;

–8. Create trigger that employee cannot change the order id


CREATE TRIGGER trigger_insurance_payment
ON Bill
FOR UPDATE
AS
BEGIN
IF UPDATE(insurance_payment)
BEGIN
PRINT 'Cannot modify the salary'
ROLLBACK TRANSACTION
END
END
--test
UPDATE Bill
set insurance_payment = $120.00
where order_id = '0107'

–9.

When inserting a new order, check that the order id exists in "ORDERED_DRUGS"
SELECT order_id
FROM "ORDERED_DRUGS"
WHERE EXISTS
(SELECT order_id FROM Bill WHERE order_id = 'O111');
--5. Employee Validation
When an employee is added, the employee type should be one of:
1. Pharmacist
2. CPhT
3.Pharmacy clerk
4. Pharmacy assistant
Except Pharmacy clerk , every other role requires a license.

CREATE OR REPLACE TRIGGER Validate_Employee


BEFORE INSERT OR UPDATE ON EMPLOYEE
FOR EACH ROW
BEGIN
IF LOWER(:NEW.role) != 'Pharmacy clerk' OR LOWER(:NEW.role != 'pharmacist') OR
LOWER(:NEW.role != 'cpht') OR
LOWER(:NEW.role != 'Pharmacy assistant')
THEN
RAISE_APPLICATION_ERROR(-20000, 'Invalid role given for employee');
END IF;
IF :NEW.license := NULL AND LOWER(:new.role) != 'Pharmacy clerk'
THEN
RAISE_APPLICATION_ERROR(-20000, 'Can not leave license blank for anyone except
Pharmacy clerk');
END IF;
END;
--te a trigger so that every time you delete the doctor id in the prescription table,
--it will automatically delete the corresponding lines in the Bill table
create trigger delete_DoctorID
on Prescription
for DELETE
AS
BEGIN
delete from PRESCRIBED_DRUGS
where Doctor_ID in (
select Doctor_ID
from deleted)
END
drop trigger delete_DoctorID
--test
delete from Prescription where Doctor_ID = 'P105'

10. Count the number of customers in each range of age (Tableau)

3. LINH CHI PART


–1. Get the information to view insurance percentage
SELECT Customer_id, order_id, full_name, phone, gender, address, date_of_birth,
insurance_id
FROM Customer
INNER JOIN INSURANCE
ON Customer.Insurance=Insurance.Insurance
ORDER BY Insurance_ID;
–2. Manage the amount of gender from customers (VIEW)
CREATE VIEW gender.customers_info AS
SELECT Customer_id, order_id, full_name, phone, gender, address, date_of_birth,
insurance_id
From Customer_id
INNER JOIN GENDER
ON Customer.Gender=Gender.Gender
SELECT *FROM gender.customers_info

–3. Find the customer with the last name Bùi and sorts by ascending
select *from Customer
where fullname like B 'Bùi%'
ORDER BY fullname ASC;

–4. Update medicine name (TRANSACTION)


update MEDICINE
set Manufacturer = 'Ha Tay Pharmaceutical Joint Stock Company'
WHERE drug_name = 'Mescaline'
commit
SELECT * from Medicine

–5. Retrieve the information when customer payment is between $20 and $50.
CREATE PROCEDURE ListBill_byprice @minprice int, @maxprice int
AS
BEGIN
SELECT order_id, customer_payment
FROM Bill WHERE customer_payment between @minprice and @maxprice
END

DECLARE @price int;


EXECUTE @price = ListBill_byprice $20, $50;
PRINT @price;

drop PROCEDURE ListBill_byprice

– 6. Find the highest salary of employee


SELECT MAX(salary)
FROM Employee

–7. Count the number of customers with birthday between May 2rd and July 8th
SELECT Date_of_birth, COUNT(*) AS NumberOfCusWithBirthday
FROM CUSTOMER
WHERE Date_of_birth
BETWEEN ('2002-05-02') AND ('2002-07-08')
GROUP BY Date_of_birth;

–8. Find the order with the Expiry Date < 2023-12-21 and make disposal notification
SELECT drug_name , batch_number, Manufacturer, expiry_date
FROM Medicine
WHERE expiry_date < ‘2023-12-21’
ORDER BY expiry_date ASC;
---B110
SELECT Order_ID
FROM ORDERED_DRUGS
WHERE batch_number = 'B110'

–9. Count the number of customers who live in Cau Giay District
SELECT Customer.address, COUNT(*) AS NUMBEROFCUSTOMER
FROM CUSTOMER
INNER JOIN "ORDER"
ON Customer.order_id = "Order".order_id
GROUP BY Customer.address
HAVING Customer.address = 'Cầu Giấy’
ORDER BY Customer.address DESC;

10/ Percentage of customer’s gender (Female and Male) <Tableau>


IV. Conclusion
This report has given a representative picture of th in Pharmacy Store Management. We
have applied the business rules and business narratives in the designed database and
come up with some solutions to practical business tasks using a wide range of statements
from MySQL such as SELECT FROM WHERE ORDER BY GROUP BY HAVING,
TRIGGER, VIEW, PROCEDURE, TRANSACTION, etc.

This report is created with our own experience after thorough research. Nevertheless, we
are well aware of the shortcomings and limited scope of our study since we are only
undergraduates. This database can help Pharmacy store and manage both billing and drug
inventory which helps in maintaining the records of medicines, employees, and
customers and also reduces the work of searching the medicine

V. Contributions

No. Name ID Tasks


Abstract, Introduction (30%), Analyzing
and designing the database (50%), 10
1 Nguyễn Tuấn Thành 20070980
business questions and use SQL to find
their answers, Paper designing
Introduction (70%), Analyzing and
designing the database (20%), 10
2 Vũ Linh Chi 20070681
business questions and use SQL to find
their answers
Analyzing and designing the database
3 Nguyễn Lâm Tường 20070799 (30%), 10 business questions and use
SQL to find their answers

You might also like