Content-Length: 646850 | pFad | http://github.com/iamAntimPal/LeetCode_SQL_Database/commit/16ca2730fdcf3d42e05e60567f2c6f6f5d434405

44 Update readme.md · iamAntimPal/LeetCode_SQL_Database@16ca273 · GitHub
Skip to content

Commit 16ca273

Browse files
committed
Update readme.md
1 parent c33fa4f commit 16ca273

File tree

1 file changed

+223
-0
lines changed
  • LeetCode SQL 50 Solution/prosnal_database

1 file changed

+223
-0
lines changed
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
Below is a well-structured `README.md` that documents the database schema, sample data, and queries for the provided SQL code. This file can be added to your repository for clarity and organization.
2+
3+
```md
4+
# Prosnal Database Example
5+
6+
This repository contains SQL scripts for creating and populating a sample database called `prosnal_database`. The database includes multiple tables and queries demonstrating joins and calculations. The following sections describe the database schema, sample data insertion, and example queries.
7+
8+
---
9+
10+
## Database and Tables
11+
12+
### 1. Create and Use Database
13+
```sql
14+
CREATE DATABASE IF NOT EXISTS prosnal_database;
15+
USE prosnal_database;
16+
```
17+
- This command creates the database `prosnal_database` if it does not exist and sets it as the current working database.
18+
19+
---
20+
21+
### 2. Employees Table
22+
```sql
23+
CREATE TABLE IF NOT EXISTS Employees (
24+
Id INT,
25+
Name VARCHAR(255),
26+
Salary INT,
27+
Department VARCHAR(255)
28+
);
29+
```
30+
- **Description:**
31+
Contains employee information such as `Id`, `Name`, `Salary`, and `Department`.
32+
33+
#### Sample Data:
34+
```sql
35+
INSERT INTO Employees (Id, Name, Salary, Department)
36+
VALUES (1, 'John Doe', 50000, 'HR'),
37+
(2, 'Jane Smith', 60000, 'Finance'),
38+
(3, 'Mike Johnson', 70000, 'IT'),
39+
(4, 'Sarah Black', 60000, 'Finance'),
40+
(5, 'David White', 70000, 'IT');
41+
```
42+
43+
---
44+
45+
### 3. Projects Table
46+
```sql
47+
CREATE TABLE IF NOT EXISTS Projects (
48+
Id INT,
49+
Name VARCHAR(255),
50+
Department VARCHAR(255)
51+
);
52+
```
53+
- **Description:**
54+
Contains project details including project `Id`, `Name`, and the corresponding `Department`.
55+
56+
#### Sample Data:
57+
```sql
58+
INSERT INTO Projects (Id, Name, Department)
59+
VALUES (1, 'Project A', 'IT'),
60+
(2, 'Project B', 'Finance'),
61+
(3, 'Project C', 'IT');
62+
```
63+
64+
---
65+
66+
### 4. EmployeeProjects Table
67+
```sql
68+
CREATE TABLE IF NOT EXISTS EmployeeProjects (
69+
EmployeeId INT,
70+
ProjectId INT
71+
);
72+
```
73+
- **Description:**
74+
Associates employees with projects.
75+
76+
#### Sample Data:
77+
```sql
78+
INSERT INTO EmployeeProjects (EmployeeId, ProjectId)
79+
VALUES (1, 1),
80+
(1, 2),
81+
(2, 1),
82+
(3, 1),
83+
(3, 3),
84+
(4, 2),
85+
(5, 1);
86+
```
87+
88+
---
89+
90+
### 5. Users and Sessions Tables
91+
#### Users Table
92+
```sql
93+
CREATE TABLE users (
94+
id INT PRIMARY KEY,
95+
name VARCHAR(50),
96+
email VARCHAR(100)
97+
);
98+
```
99+
- **Description:**
100+
Contains user information with unique `id`, `name`, and `email`.
101+
102+
#### Sample Data:
103+
```sql
104+
INSERT INTO users (id, name, email)
105+
VALUES (1, 'John Doe', 'john.doe@example.com'),
106+
(2, 'Jane Smith', 'antima@example.com');
107+
```
108+
109+
#### Sessions Table
110+
```sql
111+
CREATE TABLE sessions (
112+
id INT PRIMARY KEY,
113+
user_id INT,
114+
session_date DATE
115+
);
116+
```
117+
- **Description:**
118+
Records session data with session `id`, associated `user_id`, and the `session_date`.
119+
120+
#### Sample Data:
121+
```sql
122+
INSERT INTO sessions (id, user_id, session_date)
123+
VALUES (1, 1, '2022-01-01'),
124+
(2, 1, '2022-01-02'),
125+
(3, 2, '2022-01-03');
126+
```
127+
128+
---
129+
130+
### 6. Products and Orders Tables
131+
#### Products Table
132+
```sql
133+
CREATE TABLE IF NOT EXISTS products (
134+
id INT PRIMARY KEY,
135+
name VARCHAR(50),
136+
price DECIMAL(10, 2)
137+
);
138+
```
139+
- **Description:**
140+
Contains product details such as `id`, `name`, and `price`.
141+
142+
#### Sample Data:
143+
```sql
144+
INSERT INTO products (id, name, price)
145+
VALUES (1, 'Product A', 10.99),
146+
(2, 'Product B', 20.99),
147+
(3, 'Product C', 30.99);
148+
```
149+
150+
#### Orders Table
151+
```sql
152+
CREATE TABLE IF NOT EXISTS orders (
153+
id INT PRIMARY KEY,
154+
product_id INT,
155+
quantity INT
156+
);
157+
```
158+
- **Description:**
159+
Stores order details including order `id`, associated `product_id`, and order `quantity`.
160+
161+
#### Sample Data:
162+
```sql
163+
INSERT INTO orders (id, product_id, quantity)
164+
VALUES (1, 1, 5),
165+
(2, 2, 3),
166+
(3, 3, 1),
167+
(4, 1, 2),
168+
(5, 2, 4);
169+
```
170+
171+
---
172+
173+
## Example Queries
174+
175+
### Query 1: List Employee Projects
176+
Join the **Employees**, **EmployeeProjects**, and **Projects** tables to list each employee's project details.
177+
```sql
178+
SELECT e.Name AS EmployeeName, e.Department, p.Name AS ProjectName, p.Department
179+
FROM Employees e
180+
JOIN EmployeeProjects ep ON e.Id = ep.EmployeeId
181+
JOIN Projects p ON ep.ProjectId = p.Id;
182+
```
183+
184+
### Query 2: List User Sessions
185+
Join the **users** and **sessions** tables to list the session dates for each user.
186+
```sql
187+
SELECT u.name AS user_name, s.session_date
188+
FROM users u
189+
JOIN sessions s ON u.id = s.user_id;
190+
```
191+
192+
### Query 3: Calculate Order Totals
193+
Join the **products** and **orders** tables to calculate the total price for each order.
194+
```sql
195+
SELECT p.name AS product_name, o.quantity, p.price * o.quantity AS total_price
196+
FROM products p
197+
JOIN orders o ON p.id = o.product_id;
198+
```
199+
200+
---
201+
202+
## File Structure
203+
```
204+
Prosnal_Database/
205+
│── README.md
206+
│── schema.sql -- Contains all CREATE TABLE and INSERT statements.
207+
│── queries.sql -- Contains sample SELECT queries.
208+
│── sample_data.csv -- (Optional) CSV files for sample data.
209+
```
210+
211+
---
212+
213+
## Useful Links
214+
- [MySQL Documentation](https://dev.mysql.com/doc/)
215+
- [W3Schools SQL Tutorial](https://www.w3schools.com/sql/)
216+
- [Pandas Documentation](https://pandas.pydata.org/docs/)
217+
218+
---
219+
220+
This `README.md` provides a comprehensive overview of the database creation, data insertion, and query examples. Let me know if you need any modifications or further details!
221+
```
222+
223+
This documentation should help users understand the purpose of each table and query, and it organizes your code in a clear and accessible way.

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/iamAntimPal/LeetCode_SQL_Database/commit/16ca2730fdcf3d42e05e60567f2c6f6f5d434405

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy