Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Screenshot 2023-05-24 at 20.41.29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
198 changes: 198 additions & 0 deletions db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
-- MySQL dump 10.13 Distrib 8.0.32, for macos13.0 (arm64)
--
-- Host: localhost Database: be_pro
-- ------------------------------------------------------
-- Server version 8.0.32

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Current Database: `be_pro`
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `be_pro` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;

USE `be_pro`;

--
-- Table structure for table `classes`
--

DROP TABLE IF EXISTS `classes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `classes` (
`class_id` int NOT NULL AUTO_INCREMENT,
`class_name` varchar(255) DEFAULT NULL,
`prof_id` int DEFAULT NULL,
`course_id` int DEFAULT NULL,
`room_id` int DEFAULT NULL,
PRIMARY KEY (`class_id`),
UNIQUE KEY `room_id` (`room_id`),
KEY `fk_professor_class` (`prof_id`),
KEY `fk_courses_class` (`course_id`),
CONSTRAINT `fk_courses_class` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`),
CONSTRAINT `fk_professor_class` FOREIGN KEY (`prof_id`) REFERENCES `professors` (`prof_id`),
CONSTRAINT `fk_room_class` FOREIGN KEY (`room_id`) REFERENCES `rooms` (`room_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `classes`
--

LOCK TABLES `classes` WRITE;
/*!40000 ALTER TABLE `classes` DISABLE KEYS */;
INSERT INTO `classes` VALUES (1,'classA',1,1,1),(2,'classB',1,2,2),(3,'classC',2,3,3);
/*!40000 ALTER TABLE `classes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `courses`
--

DROP TABLE IF EXISTS `courses`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `courses` (
`course_id` int NOT NULL AUTO_INCREMENT,
`course_name` varchar(50) DEFAULT NULL,
PRIMARY KEY (`course_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `courses`
--

LOCK TABLES `courses` WRITE;
/*!40000 ALTER TABLE `courses` DISABLE KEYS */;
INSERT INTO `courses` VALUES (1,'courseA'),(2,'courseB'),(3,'courseC');
/*!40000 ALTER TABLE `courses` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `enrolls`
--

DROP TABLE IF EXISTS `enrolls`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `enrolls` (
`stud_id` int NOT NULL,
`class_id` int NOT NULL,
`grade` varchar(3) DEFAULT NULL,
PRIMARY KEY (`stud_id`,`class_id`),
KEY `fk_class_enroll` (`class_id`),
CONSTRAINT `fk_class_enroll` FOREIGN KEY (`class_id`) REFERENCES `classes` (`class_id`),
CONSTRAINT `fk_student_enroll` FOREIGN KEY (`stud_id`) REFERENCES `students` (`stud_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `enrolls`
--

LOCK TABLES `enrolls` WRITE;
/*!40000 ALTER TABLE `enrolls` DISABLE KEYS */;
INSERT INTO `enrolls` VALUES (1,1,'A'),(1,2,'B'),(2,1,'A'),(2,2,'B'),(2,3,'A'),(3,1,'B'),(3,2,'C'),(4,1,'A'),(4,2,'D'),(4,3,'B');
/*!40000 ALTER TABLE `enrolls` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `professors`
--

DROP TABLE IF EXISTS `professors`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `professors` (
`prof_id` int NOT NULL AUTO_INCREMENT,
`prof_lname` varchar(50) DEFAULT NULL,
`prof_fname` varchar(50) DEFAULT NULL,
PRIMARY KEY (`prof_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `professors`
--

LOCK TABLES `professors` WRITE;
/*!40000 ALTER TABLE `professors` DISABLE KEYS */;
INSERT INTO `professors` VALUES (1,'prof_A','A'),(2,'prof_B','B'),(3,'prof_C','C'),(4,'prof_D','D');
/*!40000 ALTER TABLE `professors` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `rooms`
--

DROP TABLE IF EXISTS `rooms`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `rooms` (
`room_id` int NOT NULL AUTO_INCREMENT,
`room_loc` varchar(50) DEFAULT NULL,
`room_cap` varchar(50) DEFAULT NULL,
PRIMARY KEY (`room_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `rooms`
--

LOCK TABLES `rooms` WRITE;
/*!40000 ALTER TABLE `rooms` DISABLE KEYS */;
INSERT INTO `rooms` VALUES (1,'room1','30'),(2,'room2','33'),(3,'room3','28');
/*!40000 ALTER TABLE `rooms` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `students`
--

DROP TABLE IF EXISTS `students`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `students` (
`stud_id` int NOT NULL AUTO_INCREMENT,
`stud_lname` varchar(50) DEFAULT NULL,
`stud_fname` varchar(50) DEFAULT NULL,
`stud_street` varchar(255) DEFAULT NULL,
`stud_city` varchar(50) DEFAULT NULL,
`stud_zip` varchar(10) DEFAULT NULL,
PRIMARY KEY (`stud_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `students`
--

LOCK TABLES `students` WRITE;
/*!40000 ALTER TABLE `students` DISABLE KEYS */;
INSERT INTO `students` VALUES (1,'stud_A','sA','street1','city1','001'),(2,'stud_B','sB','street2','city2','002'),(3,'stud_C','sC','street3','city3','003'),(4,'stud_D','sD','street4','city4','004');
/*!40000 ALTER TABLE `students` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2023-05-26 0:39:18
8 changes: 8 additions & 0 deletions sol-1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SELECT stock_name, SUM(
CASE
WHEN operation = 'Sell' THEN price
ELSE - price
END
) as capital_gain_loss
FROM Stocks
GROUP BY stock_name
23 changes: 23 additions & 0 deletions sol-2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
select
t1.category,
count(t2.category) as accounts_count
from (
SELECT 'Low Salary' AS category
UNION ALL
SELECT
'Average Salary' AS category
UNION ALL
SELECT
'High Salary' AS category
) as t1
LEFT JOIN (
SELECT
CASE
WHEN income < 20000 THEN 'Low Salary'
WHEN income >= 20000
AND income <= 50000 THEN 'Average Salary'
ELSE 'High Salary'
END AS category
FROM Accounts
) AS t2 ON t1.category = t2.category
group by t2.category
52 changes: 52 additions & 0 deletions sol-3-create-tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
CREATE TABLE professors (
prof_id int NOT NULL AUTO_INCREMENT,
prof_lname VARCHAR(50),
prof_fname VARCHAR(50),
PRIMARY KEY (prof_id)
);

CREATE TABLE students (
stud_id int NOT NULL AUTO_INCREMENT,
stud_lname VARCHAR(50),
stud_fname VARCHAR(50),
stud_street VARCHAR(255),
stud_city VARCHAR(50),
stud_zip VARCHAR(10),
PRIMARY KEY (stud_id)
);


CREATE TABLE rooms (
room_id int NOT NULL AUTO_INCREMENT,,
room_loc VARCHAR(50),
room_cap VARCHAR(50),
PRIMARY KEY (room_id)
);

CREATE TABLE courses (
course_id int NOT NULL AUTO_INCREMENT,,
course_name VARCHAR(50),
PRIMARY KEY (course_id)
);

CREATE TABLE classes (
class_id int NOT NULL AUTO_INCREMENT,,
class_name VARCHAR(255),
prof_id int,
course_id int,
room_id int,
PRIMARY KEY (class_id),
UNIQUE (room_id),
CONSTRAINT fk_professor_class FOREIGN KEY (prof_id) REFERENCES professors(prof_id),
CONSTRAINT fk_room_class FOREIGN KEY (room_id) REFERENCES rooms(room_id),
CONSTRAINT fk_courses_class FOREIGN KEY (course_id) REFERENCES courses(course_id)
);

CREATE TABLE enrolls (
stud_id int,
class_id int,
grade VARCHAR(3),
PRIMARY KEY (stud_id, class_id),
CONSTRAINT fk_student_enroll FOREIGN KEY (stud_id) REFERENCES students(stud_id),
CONSTRAINT fk_class_enroll FOREIGN KEY (class_id) REFERENCES classes(class_id)
);
Loading