0% found this document useful (0 votes)
20 views4 pages

DWM 3

The document outlines the creation of a database named 'MedicineCompany' with tables for Customers, Medicines, Employees, Time, and Sales_Fact. It includes SQL commands for inserting data into these tables, as well as queries to calculate total revenue from sales and identify the top-selling medicine by employee. The document demonstrates the structure and relationships within the database, including foreign key constraints.

Uploaded by

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

DWM 3

The document outlines the creation of a database named 'MedicineCompany' with tables for Customers, Medicines, Employees, Time, and Sales_Fact. It includes SQL commands for inserting data into these tables, as well as queries to calculate total revenue from sales and identify the top-selling medicine by employee. The document demonstrates the structure and relationships within the database, including foreign key constraints.

Uploaded by

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

EXPERIMENT NO.

3
mysql> CREATE DATABASE MedicineCompany;

Query OK, 1 row affected (0.01 sec)

mysql> USE MedicineCompany;

Database changed

mysql> CREATE TABLE Customer (

-> Cust_Id INT PRIMARY KEY,

-> Cust_Name VARCHAR(100) NOT NULL,

-> Type VARCHAR(50),

-> Contact VARCHAR(15),

-> Address VARCHAR(255)

-> );

Query OK, 0 rows affected (0.05 sec)

mysql> INSERT INTO Customer (Cust_Id, Cust_Name, Type, Contact, Address)

-> VALUES

-> (1, 'Aarav Sharma', 'Regular', '9876543210', '123 Wellness Street,


Mumbai, Maharashtra'),

-> (2, 'Isha Patel', 'Premium', '8765432109', '456 Care Avenue, Delhi,
Delhi'),

-> (3, 'Ravi Kumar', 'Regular', '9654321098', '789 Health Road,


Bengaluru, Karnataka'),

-> (4, 'Priya Singh', 'Premium', '9543210987', '321 Remedy Lane,


Chennai, Tamil Nadu'),

-> (5, 'Vikram Desai', 'Regular', '9432109876', '654 Cure Colony,


Hyderabad, Telangana');

Query OK, 5 rows affected (0.01 sec)

Records: 5 Duplicates: 0 Warnings: 0

mysql> CREATE TABLE Medicine (

-> Med_Id INT PRIMARY KEY,

-> Name VARCHAR(100) NOT NULL,

-> Manufacturing_date DATE,

-> Expiry_date DATE,

-> Dosage VARCHAR(50)


-> );

Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO Medicine (Med_Id, Name, Manufacturing_date, Expiry_date,


Dosage)

-> VALUES

-> (1, 'Paracetamol', '2023-01-15', '2025-01-14', '500 mg'),

-> (2, 'Amoxicillin', '2023-06-01', '2024-12-31', '250 mg'),

-> (3, 'Cetirizine', '2023-03-20', '2026-03-19', '10 mg'),

-> (4, 'Ibuprofen', '2022-11-10', '2024-11-09', '200 mg'),

-> (5, 'Metformin', '2023-02-05', '2025-02-04', '500 mg');

Query OK, 5 rows affected (0.01 sec)

Records: 5 Duplicates: 0 Warnings: 0

mysql> CREATE TABLE Employee (

-> Emp_Id INT PRIMARY KEY,

-> Emp_Name VARCHAR(100) NOT NULL,

-> Role VARCHAR(50),

-> Rating DECIMAL(3, 1),

-> Dept_Id INT,

-> Dept_Name VARCHAR(100)

-> );

Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO Employee (Emp_Id, Emp_Name, Role, Rating, Dept_Id,


Dept_Name)

-> VALUES

-> (1, 'Ravi Kumar', 'Software Engineer', 4.5, 101, 'IT'),

-> (2, 'Priya Singh', 'Marketing Manager', 4.7, 102, 'Marketing'),

-> (3, 'Aarav Patel', 'Data Analyst', 4.2, 101, 'IT'),

-> (4, 'Meera Sharma', 'HR Specialist', 4.0, 103, 'Human Resources'),

-> (5, 'Arjun Desai', 'Sales Executive', 3.8, 104, 'Sales');

Query OK, 5 rows affected (0.01 sec)

Records: 5 Duplicates: 0 Warnings: 0

mysql> CREATE TABLE Time (


-> Date DATE PRIMARY KEY,

-> Year INT,

-> Month INT,

-> Day_of_week VARCHAR(10)

-> );

Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO Time (Date, Year, Month, Day_of_week)

-> VALUES

-> ('2024-01-15', 2024, 1, 'Monday'),

-> ('2024-02-20', 2024, 2, 'Tuesday'),

-> ('2024-03-25', 2024, 3, 'Monday'),

-> ('2024-04-10', 2024, 4, 'Wednesday'),

-> ('2024-05-05', 2024, 5, 'Sunday');

Query OK, 5 rows affected (0.01 sec)

Records: 5 Duplicates: 0 Warnings: 0

mysql> CREATE TABLE Sales_Fact (

-> Emp_Id INT,

-> Cust_Id INT,

-> Med_Id INT,

-> Date DATE,

-> Top_Selling_Med VARCHAR(100),

-> Discount DECIMAL(5, 2),

-> Revenue DECIMAL(10, 2),

-> Total_Profit DECIMAL(10, 2),

-> PRIMARY KEY (Emp_Id, Cust_Id, Med_Id, Date),

-> FOREIGN KEY (Emp_Id) REFERENCES Employee(Emp_Id),

-> FOREIGN KEY (Cust_Id) REFERENCES Customer(Cust_Id),

-> FOREIGN KEY (Med_Id) REFERENCES Medicine(Med_Id),

-> FOREIGN KEY (Date) REFERENCES Time(Date)

-> );

Query OK, 0 rows affected (0.09 sec)

mysql> INSERT INTO Sales_Fact (Emp_Id, Cust_Id, Med_Id, Date,


Top_Selling_Med, Discount, Revenue, Total_Profit)
-> VALUES

-> (1, 1, 1, '2024-01-15', 'Paracetamol', 10.00, 500.00, 150.00),

-> (2, 2, 2, '2024-02-20', 'Amoxicillin', 5.00, 750.00, 300.00),

-> (3, 3, 3, '2024-03-25', 'Cetirizine', 15.00, 300.00, 120.00),

-> (4, 4, 4, '2024-04-10', 'Ibuprofen', 20.00, 400.00, 160.00),

-> (5, 5, 5, '2024-05-05', 'Metformin', 8.00, 600.00, 200.00);

Query OK, 5 rows affected (0.01 sec)

Records: 5 Duplicates: 0 Warnings: 0

mysql> SELECT Name, SUM(Revenue) AS Total_Revenue

-> FROM Sales_Fact

-> JOIN Medicine ON Sales_Fact.Med_Id = Medicine.Med_Id

-> GROUP BY Name;

+-------------+---------------+

| Name | Total_Revenue |

+-------------+---------------+

| Paracetamol | 500.00 |

| Amoxicillin | 750.00 |

| Cetirizine | 300.00 |

| Ibuprofen | 400.00 |

| Metformin | 600.00 |

+-------------+---------------+

5 rows in set (0.01 sec)

mysql> SELECT Emp_Name, Top_Selling_Med, SUM(Revenue) AS Total_Sales

-> FROM Sales_Fact

-> JOIN Employee ON Sales_Fact.Emp_Id = Employee.Emp_Id

-> GROUP BY Emp_Name, Top_Selling_Med

-> ORDER BY Total_Sales DESC

-> LIMIT 1;

+-------------+-----------------+-------------+

| Emp_Name | Top_Selling_Med | Total_Sales |

+-------------+-----------------+-------------+

| Priya Singh | Amoxicillin | 750.00 |

+-------------+-----------------+-------------+

1 row in set (0.00 sec)

You might also like