Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| miniproject |
| mysql |
| performance_schema |
| practice |
| test |
+--------------------+
6 rows in set (0.02 sec)
mysql> create database poe;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| miniproject |
| mysql |
| performance_schema |
| poe |
| practice |
| test |
+--------------------+
7 rows in set (0.00 sec)
mysql> use poe;
Database changed
mysql> create table company(
-> company_id int() primary key,
-> comapany_name varchar(30),
-> contact_person varchar(30),
-> contact-email varchar(50) not null,
-> contact_number varchar(12));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ')
primary key,
comapany_name varchar(30),
contact_person varchar(30),
contact-em' at line 2
mysql> create table company(
-> company_id int primary key,
-> comapany_name varchar(30),
-> contact_person varchar(30),
-> contact-email varchar(50) not null,
-> contact_number varchar(12));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '-email
varchar(50) not null,
contact_number varchar(12))' at line 5
mysql> create table company(
-> company_id int primary key,
-> comapany_name varchar(30),
-> contact_person varchar(30),
-> contact_email varchar(50) not null,
-> contact_number varchar(12));
Query OK, 0 rows affected (0.02 sec)
mysql> show table
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> show table;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> show tables;
+---------------+
| Tables_in_poe |
+---------------+
| company |
+---------------+
1 row in set (0.00 sec)
mysql> desc company;
+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| company_id | int(11) | NO | PRI | NULL | |
| comapany_name | varchar(30) | YES | | NULL | |
| contact_person | varchar(30) | YES | | NULL | |
| contact_email | varchar(50) | NO | | NULL | |
| contact_number | varchar(12) | YES | | NULL | |
+----------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
mysql> create table service(
-> service_id int primary key,
-> service_name varchar(50),
-> description varchar(100),
-> price decimal(9,2),
-> company_id int,
-> constraint fk foreign key (company_id) references company(company_id)
);
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
+---------------+
| Tables_in_poe |
+---------------+
| company |
| service |
+---------------+
2 rows in set (0.00 sec)
mysql> desc service;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| service_id | int(11) | NO | PRI | NULL | |
| service_name | varchar(50) | YES | | NULL | |
| description | varchar(100) | YES | | NULL | |
| price | decimal(9,2) | YES | | NULL | |
| company_id | int(11) | YES | MUL | NULL | |
+--------------+--------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
mysql> insert into company value(101,"J.K.Mishra","Ortho",3);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into company value(1,"company A","John doe","john.doe@example.
com",123-456-7890);
Query OK, 1 row affected (0.01 sec)
mysql> select * from company;
+------------+---------------+----------------+----------------------
+----------------+
| company_id | comapany_name | contact_person | contact_email |
contact_number |
+------------+---------------+----------------+----------------------
+----------------+
| 1 | company A | John doe |
[email protected] | -8223
|
+------------+---------------+----------------+----------------------
+----------------+
1 row in set (0.01 sec)
;
ERROR:
No query specified
mysql> delect contact_number from company;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'delect
contact_number from company' at line 1
mysql> truncate company;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint
(`poe`.`service`, CONSTRAINT `fk` FOREIGN KEY (`company_id`) REFERENCES
`poe`.`company` (`company_id`))
mysql> truncate table company;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint
(`poe`.`service`, CONSTRAINT `fk` FOREIGN KEY (`company_id`) REFERENCES
`poe`.`company` (`company_id`))
mysql> DELETE FROM company
-> WHERE company_id = 1;
Query OK, 1 row affected (0.00 sec)
mysql> DELETE FROM company
-> WHERE company_id = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> select* from company;
Empty set (0.00 sec)
mysql> insert into company value(1,"company A","John
doe","
[email protected]","123-456-7890");
Query OK, 1 row affected (0.01 sec)
mysql> insert into company value(1,"company A","John
doe","
[email protected]","123-456-7890");
com","1insert into company value(1,"company A","John
doe","john.doe@exam;ple.com","123-456-7890");
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> insert into company value(1,"company A","John
doe","john.doe@exam;ple.com","143-456-7890");
.com","insert into company value(2,"company B","Jane
doe","jane.doe@exam;ple.com","143-456-7890");
Query OK, 1 row affected (0.01 sec)
mysql> insert into company value(3,"company C","Jane
doe","jane.doe@exam;ple.com","143-456-7890");
.com","143-456-7890");
insert into company value(4,"company D","
Mishell","Mi.doe@exam;ple.com","143-456-7890");
Query OK, 1 row affected (0.01 sec)
mysql> select * from company;
+------------+---------------+----------------+-----------------------
+----------------+
| company_id | comapany_name | contact_person | contact_email |
contact_number |
+------------+---------------+----------------+-----------------------
+----------------+
| 1 | company A | John doe |
[email protected] | 123-456-
7890 |
| 2 | company B | Jane doe | jane.doe@exam;ple.com | 143-456-
7890 |
| 4 | company D | Mishell | Mi.doe@exam;ple.com | 143-456-
7890 |
+------------+---------------+----------------+-----------------------
+----------------+
3 rows in set (0.00 sec)
mysql> DELETE FROM company
-> WHERE company_id = 4;
Query OK, 1 row affected (0.01 sec)
mysql> insert into company value(3,"company C","
Mishell","Mi.doe@exam;ple.com","143-456-7890");
Query OK, 1 row affected (0.01 sec)
mysql> insert into company value(4,"company D","
Mishell","Mi.doe@exam;ple.com","143-456-7890");
om","14insert into company value(4,"company D","
Emily","Emii.doe@exam;ple.com","143-456-7890");
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO service (service_id, service_name, description, price,
company_id)
-> VALUES
-> (1, 'Web Development', 'Building custom websites', 500.00, 1),
-> (2, 'Network Setup', 'Setting up local area networks', 800.00, 1),
-> (3, 'Database Management', 'Managing and optimizing databases', 700.00, 2),
-> (4, 'Cybersecurity Audit', 'Auditing and securing networks', 1000.00, 2),
-> (5, 'Cloud Services', 'Implementing cloud solutions', 900.00, 3),
-> (6, 'IT Support', 'Providing technical support', 600.00, 3),
-> (7, 'Software Development', 'Developing custom software', 1200.00, 4),
-> (8, 'Data Analysis', 'Analyzing and interpreting data', 850.00, 4);
Query OK, 8 rows affected (0.01 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> select * from service
-> where price between 500 and 1000;
+------------+---------------------+-----------------------------------+---------
+------------+
| service_id | service_name | description | price |
company_id |
+------------+---------------------+-----------------------------------+---------
+------------+
| 1 | Web Development | Building custom websites | 500.00 |
1 |
| 2 | Network Setup | Setting up local area networks | 800.00 |
1 |
| 3 | Database Management | Managing and optimizing databases | 700.00 |
2 |
| 4 | Cybersecurity Audit | Auditing and securing networks | 1000.00 |
2 |
| 5 | Cloud Services | Implementing cloud solutions | 900.00 |
3 |
| 6 | IT Support | Providing technical support | 600.00 |
3 |
| 8 | Data Analysis | Analyzing and interpreting data | 850.00 |
4 |
+------------+---------------------+-----------------------------------+---------
+------------+
7 rows in set (0.01 sec)
mysql> select company_id,comapany_name
-> from company
-> where price >800.3;
ERROR 1054 (42S22): Unknown column 'price' in 'where clause'
mysql> SELECT DISTINCT c.company_id, c.company_name, c.contact_person,
c.contact_email, c.contact_number
-> FROM company c
-> JOIN service s ON c.company_id = s.company_id
-> WHERE s.price > 800.3;
ERROR 1054 (42S22): Unknown column 'c.company_name' in 'field list'
mysql> SELECT *
-> FROM company c
-> JOIN service s ON c.company_id = s.company_id
-> WHERE s.price > 800.3;
+------------+---------------+----------------+-----------------------
+----------------+------------+----------------------
+---------------------------------+---------+------------+
| company_id | comapany_name | contact_person | contact_email |
contact_number | service_id | service_name | description
| price | company_id |
+------------+---------------+----------------+-----------------------
+----------------+------------+----------------------
+---------------------------------+---------+------------+
| 2 | company B | Jane doe | jane.doe@exam;ple.com | 143-456-
7890 | 4 | Cybersecurity Audit | Auditing and securing networks |
1000.00 | 2 |
| 3 | company C | Mishell | Mi.doe@exam;ple.com | 143-456-
7890 | 5 | Cloud Services | Implementing cloud solutions |
900.00 | 3 |
| 4 | company D | Emily | Emii.doe@exam;ple.com | 143-456-
7890 | 7 | Software Development | Developing custom software |
1200.00 | 4 |
| 4 | company D | Emily | Emii.doe@exam;ple.com | 143-456-
7890 | 8 | Data Analysis | Analyzing and interpreting data |
850.00 | 4 |
+------------+---------------+----------------+-----------------------
+----------------+------------+----------------------
+---------------------------------+---------+------------+
4 rows in set (0.01 sec)
mysql> SELECT COUNT(*) AS total_services
-> FROM service;
+----------------+
| total_services |
+----------------+
| 8 |
+----------------+
1 row in set (0.01 sec)
mysql> select avg(*)
-> from service;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '*)
from service' at line 1
mysql> select avg(price) as average price
-> from service;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'price
from service' at line 1
mysql> select avg(price) as average_price
-> from service;
+---------------+
| average_price |
+---------------+
| 818.750000 |
+---------------+
1 row in set (0.00 sec)
mysql> select c.comapany_name,s.service_name,s.service_price
-> from company c
-> join service s on company_id=service_id
-> where s.price>800;
ERROR 1054 (42S22): Unknown column 's.service_price' in 'field list'
mysql> select c.comapany_name,s.service_name,s.price
-> from company c
-> join service s on company_id=service_id
-> where s.price>800;
ERROR 1052 (23000): Column 'company_id' in on clause is ambiguous
mysql> SELECT c.company_name, s.service_name, s.price
-> FROM company c
-> JOIN service s ON c.company_id = s.company_id
-> WHERE s.price > 800;
ERROR 1054 (42S22): Unknown column 'c.company_name' in 'field list'
mysql> SELECT c.comapany_name, s.service_name, s.price
-> FROM company c
-> JOIN service s ON c.company_id = s.company_id
-> WHERE s.price > 800;
+---------------+----------------------+---------+
| comapany_name | service_name | price |
+---------------+----------------------+---------+
| company B | Cybersecurity Audit | 1000.00 |
| company C | Cloud Services | 900.00 |
| company D | Software Development | 1200.00 |
| company D | Data Analysis | 850.00 |
+---------------+----------------------+---------+
4 rows in set (0.00 sec)
mysql> -- Create Flights Table
mysql> CREATE TABLE Flights (
-> FlightID INT PRIMARY KEY,
-> FlightNumber VARCHAR(10),
-> DepartureCity VARCHAR(50),
-> ArrivalCity VARCHAR(50),
-> DepartureTime DATETIME,
-> ArrivalTime DATETIME
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Create Passengers Table
mysql> CREATE TABLE Passengers (
-> PassengerID INT PRIMARY KEY,
-> Name VARCHAR(50),
-> FlightID INT,
-> SeatNumber VARCHAR(5),
-> FOREIGN KEY (FlightID) REFERENCES Flights(FlightID)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Create Airlines Table
mysql> CREATE TABLE Airlines (
-> AirlineID INT PRIMARY KEY,
-> Name VARCHAR(50),
-> Country VARCHAR(50)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Create Aircraft Table
mysql> CREATE TABLE Aircraft (
-> AircraftID INT PRIMARY KEY,
-> Model VARCHAR(50),
-> Capacity INT,
-> AirlineID INT,
-> FOREIGN KEY (AirlineID) REFERENCES Airlines(AirlineID)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> -- Insert data into Airlines Table
mysql> INSERT INTO Airlines (AirlineID, Name, Country) VALUES
-> (1, 'Delta Airlines', 'USA'),
-> (2, 'Southwest Airlines', 'USA');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Insert data into Aircraft Table
mysql> INSERT INTO Aircraft (AircraftID, Model, Capacity, AirlineID) VALUES
-> (1, 'Boeing 737', 180, 1),
-> (2, 'Airbus A320', 160, 2);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Insert data into Flights Table
mysql> INSERT INTO Flights (FlightID, FlightNumber, DepartureCity, ArrivalCity,
DepartureTime, ArrivalTime) VALUES
-> (1, 'AA101', 'New York', 'Los Angeles', '2024-11-27 08:00:00', '2024-11-27
11:30:00'),
-> (2, 'DL202', 'New York', 'Atlanta', '2024-11-27 09:00:00', '2024-11-27
12:00:00'),
-> (3, 'SW303', 'Chicago', 'Dallas', '2024-11-27 14:00:00', '2024-11-27
16:30:00');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Insert data into Passengers Table
mysql> INSERT INTO Passengers (PassengerID, Name, FlightID, SeatNumber) VALUES
-> (1, 'John Doe', 1, '12A'),
-> (2, 'Jane Smith', 1, '12B'),
-> (3, 'Alice Johnson', 2, '15C');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT *
-> FROM Flights
-> WHERE DepartureCity = 'New York';
+----------+--------------+---------------+-------------+---------------------
+---------------------+
| FlightID | FlightNumber | DepartureCity | ArrivalCity | DepartureTime |
ArrivalTime |
+----------+--------------+---------------+-------------+---------------------
+---------------------+
| 1 | AA101 | New York | Los Angeles | 2024-11-27 08:00:00 |
2024-11-27 11:30:00 |
| 2 | DL202 | New York | Atlanta | 2024-11-27 09:00:00 |
2024-11-27 12:00:00 |
+----------+--------------+---------------+-------------+---------------------
+---------------------+
2 rows in set (0.00 sec)
mysql> SELECT Passengers.Name, Passengers.SeatNumber
-> FROM Passengers
-> JOIN Flights ON Passengers.FlightID = Flights.FlightID
-> WHERE Flights.FlightNumber = 'AA101';
+------------+------------+
| Name | SeatNumber |
+------------+------------+
| John Doe | 12A |
| Jane Smith | 12B |
+------------+------------+
2 rows in set (0.00 sec)
mysql> SELECT Flights.*
-> FROM Flights
-> JOIN Aircraft ON Flights.AircraftID = Aircraft.AircraftID
-> JOIN Airlines ON Aircraft.AirlineID = Airlines.AirlineID
-> WHERE Airlines.Name = 'Delta Airlines';
ERROR 1054 (42S22): Unknown column 'Flights.AircraftID' in 'on clause'
mysql> -- Alter the Flights table to include AircraftID
mysql> ALTER TABLE Flights ADD AircraftID INT;
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Add the foreign key constraint
mysql> ALTER TABLE Flights ADD CONSTRAINT fk_aircraft FOREIGN KEY (AircraftID)
REFERENCES Aircraft(AircraftID);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> -- Update the Flights table to associate flights with specific aircraft
mysql> UPDATE Flights SET AircraftID = 1 WHERE FlightID = 1; -- Delta Airlines
flight
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> UPDATE Flights SET AircraftID = 1 WHERE FlightID = 2; -- Delta Airlines
flight
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> UPDATE Flights SET AircraftID = 2 WHERE FlightID = 3; -- Southwest Airlines
flight
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT Flights.*
-> FROM Flights
-> JOIN Aircraft ON Flights.AircraftID = Aircraft.AircraftID
-> JOIN Airlines ON Aircraft.AirlineID = Airlines.AirlineID
-> WHERE Airlines.Name = 'Delta Airlines';
+----------+--------------+---------------+-------------+---------------------
+---------------------+------------+
| FlightID | FlightNumber | DepartureCity | ArrivalCity | DepartureTime |
ArrivalTime | AircraftID |
+----------+--------------+---------------+-------------+---------------------
+---------------------+------------+
| 1 | AA101 | New York | Los Angeles | 2024-11-27 08:00:00 |
2024-11-27 11:30:00 | 1 |
| 2 | DL202 | New York | Atlanta | 2024-11-27 09:00:00 |
2024-11-27 12:00:00 | 1 |
+----------+--------------+---------------+-------------+---------------------
+---------------------+------------+
2 rows in set (0.00 sec)
mysql> -- Create Students Table
mysql> CREATE TABLE Students (
-> StudentID INT PRIMARY KEY,
-> Name VARCHAR(50),
-> GPA DECIMAL(3, 2)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Create Scholarships Table
mysql> CREATE TABLE Scholarships (
-> ScholarshipID INT PRIMARY KEY,
-> StudentID INT,
-> Amount DECIMAL(10, 2),
-> FOREIGN KEY (StudentID) REFERENCES Students(StudentID)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> -- Insert data into Students Table
mysql> INSERT INTO Students (StudentID, Name, GPA) VALUES
-> (1, 'John Doe', 3.50),
-> (2, 'Jane Smith', 2.80),
-> (3, 'Alice Johnson', 3.20);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
mysql> -- Insert data into Scholarships Table
mysql> -- (Test inserting valid and invalid cases later)
mysql> DELIMITER $$
mysql>
mysql> CREATE TRIGGER ValidateGPA
-> BEFORE INSERT ON Scholarships
-> FOR EACH ROW
-> BEGIN
-> DECLARE gpa DECIMAL(3, 2);
->
-> -- Retrieve the GPA of the student
-> SELECT GPA INTO gpa FROM Students WHERE StudentID = NEW.StudentID;
->
-> -- Check if GPA is below 3.0
-> IF gpa < 3.0 THEN
-> SIGNAL SQLSTATE '45000'
-> SET MESSAGE_TEXT = 'Student GPA must be 3.0 or higher to receive a
scholarship.';
-> END IF;
-> END$$
Query OK, 0 rows affected (0.02 sec)
mysql>
mysql> DELIMITER ;
mysql> INSERT INTO Scholarships (ScholarshipID, StudentID, Amount)
-> VALUES (1, 1, 1000.00); -- John Doe has a GPA of 3.50 (Valid)
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO Scholarships (ScholarshipID, StudentID, Amount)
-> VALUES (2, 2, 1500.00); -- Jane Smith has a GPA of 2.80 (Invalid)
Query OK, 1 row affected (0.01 sec)
mysql> ERROR 1644 (45000): Student GPA must be 3.0 or higher to receive a
scholarship.
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'ERROR
1644 (45000): Student GPA must be 3.0 or higher to receive a scholarship.' at line
1
mysql> ERROR 1644 (45000): Student GPA must be 3.0 or higher to receive a
scholarship;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'ERROR
1644 (45000): Student GPA must be 3.0 or higher to receive a scholarship' at line 1
mysql> DELIMITER $$
mysql>
mysql> CREATE TRIGGER ValidateGPA
-> BEFORE INSERT ON Scholarships
-> FOR EACH ROW
-> BEGIN
-> DECLARE gpa DECIMAL(3, 2);
->
-> -- Retrieve the GPA of the student
-> SELECT GPA INTO gpa FROM Students WHERE StudentID = NEW.StudentID;
->
-> -- Check if GPA is below 3.0
-> IF gpa < 3.0 THEN
-> SIGNAL SQLSTATE '45000'
-> SET MESSAGE_TEXT = 'Student GPA must be 3.0 or higher to receive a
scholarship.';
-> END IF;
-> END$$
ERROR 1235 (42000): This version of MySQL doesn't yet support 'multiple triggers
with the same action time and event for one table'
mysql>
mysql> DELIMITER ;
mysql> INSERT INTO Scholarships (ScholarshipID, StudentID, Amount)
-> VALUES (1, 1, 1000.00); -- This should succeed if StudentID 1 has GPA >= 3.0
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> INSERT INTO Scholarships (ScholarshipID, StudentID, Amount)
-> VALUES (2, 2, 1500.00); -- This will fail with the error message
ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'
mysql> ERROR 1644 (45000): Student GPA must be 3.0 or higher to receive a
scholarship.
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'ERROR
1644 (45000): Student GPA must be 3.0 or higher to receive a scholarship.' at line
1
mysql> CREATE TABLE Gym (
-> gym_id INT PRIMARY KEY,
-> gym_name VARCHAR(50),
-> gym_address VARCHAR(100),
-> gym_email VARCHAR(100),
-> gym_contact BIGINT,
-> gym_rating INT
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Insert Data
mysql> INSERT INTO Gym VALUES
-> (121, 'Vanshaj', 'Saharanagar', '[email protected]', 11223365564, 5),
-> (122, 'SlimGYM', 'Asaranagar', '[email protected]', 65165125, 8),
-> (123, 'NationalGYM', 'Madinachawk', '[email protected]', 6223355, 4);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> CREATE TABLE Student (
-> stu_id INT PRIMARY KEY,
-> stu_name VARCHAR(50),
-> stu_contact BIGINT,
-> stu_age INT,
-> P_id INT
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Insert Data
mysql> INSERT INTO Student VALUES
-> (71, 'Aman Shaikh', 22113344, 19, 1),
-> (72, 'Safwan Shaikh', 55447788, 19, 1),
-> (73, 'Naveed Shaikh', 33665544, 21, 2),
-> (74, 'Saad Inamdar', 88779911, 20, 3);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> CREATE TABLE Package (
-> P_id INT PRIMARY KEY,
-> P_name VARCHAR(50),
-> P_duration INT,
-> p_amount INT
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Insert Data
mysql> INSERT INTO Package VALUES
-> (1, 'Gold', 3, 4000),
-> (2, 'Silver', 6, 8000),
-> (3, 'Platinum', 12, 12000);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> SELECT stu_name FROM Student;
+---------------+
| stu_name |
+---------------+
| Aman Shaikh |
| Safwan Shaikh |
| Naveed Shaikh |
| Saad Inamdar |
+---------------+
4 rows in set (0.00 sec)
mysql> SELECT * FROM Package WHERE p_amount > 5000;
+------+----------+------------+----------+
| P_id | P_name | P_duration | p_amount |
+------+----------+------------+----------+
| 2 | Silver | 6 | 8000 |
| 3 | Platinum | 12 | 12000 |
+------+----------+------------+----------+
2 rows in set (0.00 sec)
mysql> SELECT
-> Student.stu_id,
-> Student.stu_name,
-> Student.stu_contact,
-> Student.stu_age,
-> Package.P_name,
-> Package.P_duration,
-> Package.p_amount
-> FROM
-> Student
-> JOIN
-> Package
-> ON
-> Student.P_id = Package.P_id;
+--------+---------------+-------------+---------+----------+------------
+----------+
| stu_id | stu_name | stu_contact | stu_age | P_name | P_duration | p_amount
|
+--------+---------------+-------------+---------+----------+------------
+----------+
| 71 | Aman Shaikh | 22113344 | 19 | Gold | 3 | 4000
|
| 72 | Safwan Shaikh | 55447788 | 19 | Gold | 3 | 4000
|
| 73 | Naveed Shaikh | 33665544 | 21 | Silver | 6 | 8000
|
| 74 | Saad Inamdar | 88779911 | 20 | Platinum | 12 | 12000
|
+--------+---------------+-------------+---------+----------+------------
+----------+
4 rows in set (0.00 sec)
mysql> alter table gym
-> add Gst_number;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 2
mysql> ALTER TABLE Gym ADD GST_number VARCHAR(20);
Query OK, 3 rows affected (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> DELETE FROM Student WHERE stu_age < 20;
Query OK, 2 rows affected (0.01 sec)
mysql> create table fruit(
-> Supplier_id int primary key,
-> Fruit_name varchar(20),
-> color varchar(20),
-> Taste varchar(20),
-> price int(4),
-> Ripe_date Date);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into Fruit value
-> (1,mango,yellow,sweet,50,12/04/2024);
ERROR 1054 (42S22): Unknown column 'mango' in 'field list'
mysql> insert into Fruit value
-> (1,"mango","yellow","sweet",50,12/04/2024);
Query OK, 1 row affected (0.01 sec)
mysql> select* from fruit
-> ;
+-------------+------------+--------+-------+-------+------------+
| Supplier_id | Fruit_name | color | Taste | price | Ripe_date |
+-------------+------------+--------+-------+-------+------------+
| 1 | mango | yellow | sweet | 50 | 0000-00-00 |
+-------------+------------+--------+-------+-------+------------+
1 row in set (0.00 sec)
mysql> insert into fruit values
-> (2, 'grapes', 'Green', 'Sweet', 40, '2024-04-12'),
-> (3, 'apple', 'Red', 'Sweet', 40, '2024-04-25'),
-> (4, 'maxi', 'Khaki', 'Bitter', 30, '2024-04-18'),
-> (5, 'marlin', 'Maroon', 'Bitter', 15, '2024-05-19');
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> CREATE TABLE SupplierTable (
-> Supplier_id INT PRIMARY KEY,
-> Supplier_name VARCHAR(50),
-> Location VARCHAR(50),
-> Contact_No BIGINT
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> -- Insert Data
mysql> INSERT INTO SupplierTable VALUES
-> (1, 'FreshFruits', 'California', 1223456789),
-> (2, 'TropicalTreats', 'Hawaii', 7894561230),
-> (3, 'OrganicOrchards', 'Solapur', 7894566123),
-> (4, 'JuicyJungle', 'Mumbai', 4567891238),
-> (5, 'FarmFresh', 'Pune', 5234567893);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> ---1. List fruits that are ripe after 12/04/2024.
-> select *
-> from fruit
-> where Ripe_date>12/2/2024
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '---1.
List fruits that are ripe after 12/04/2024.
select *
from fruit
where Rip' at line 1
mysql> delete from fruit where color=yellow;
ERROR 1054 (42S22): Unknown column 'yellow' in 'where clause'
mysql> delete from fruit where supplier_id=1;
Query OK, 1 row affected (0.01 sec)
mysql> select* fruit;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'fruit'
at line 1
mysql> select* from fruit;
+-------------+------------+--------+--------+-------+------------+
| Supplier_id | Fruit_name | color | Taste | price | Ripe_date |
+-------------+------------+--------+--------+-------+------------+
| 2 | grapes | Green | Sweet | 40 | 2024-04-12 |
| 3 | apple | Red | Sweet | 40 | 2024-04-25 |
| 4 | maxi | Khaki | Bitter | 30 | 2024-04-18 |
| 5 | marlin | Maroon | Bitter | 15 | 2024-05-19 |
+-------------+------------+--------+--------+-------+------------+
4 rows in set (0.00 sec)
mysql> INSERT INTO FruitTable VALUES
-> (1, 'mango', 'Yellow', 'Sweet', 50, '2024-12-04');
ERROR 1146 (42S02): Table 'poe.fruittable' doesn't exist
mysql> INSERT INTO Fruit VALUES
-> (1, 'mango', 'Yellow', 'Sweet', 50, '2024-12-04');
Query OK, 1 row affected (0.01 sec)
mysql> select *
-> from fruit
-> where Ripe_date>12/2/2024;
+-------------+------------+--------+--------+-------+------------+
| Supplier_id | Fruit_name | color | Taste | price | Ripe_date |
+-------------+------------+--------+--------+-------+------------+
| 1 | mango | Yellow | Sweet | 50 | 2024-12-04 |
| 2 | grapes | Green | Sweet | 40 | 2024-04-12 |
| 3 | apple | Red | Sweet | 40 | 2024-04-25 |
| 4 | maxi | Khaki | Bitter | 30 | 2024-04-18 |
| 5 | marlin | Maroon | Bitter | 15 | 2024-05-19 |
+-------------+------------+--------+--------+-------+------------+
5 rows in set (0.00 sec)
mysql> select avg(price)
-> group by taste
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'group by
taste' at line 2
mysql> select avg(price)
-> from fruit
-> group by taste;
+------------+
| avg(price) |
+------------+
| 22.5000 |
| 43.3333 |
+------------+
2 rows in set (0.00 sec)
mysql> select min(price)
-> from fruit;
+------------+
| min(price) |
+------------+
| 15 |
+------------+
1 row in set (0.00 sec)
mysql> select min(price) *
-> from fruit;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'from
fruit' at line 2
mysql> select fruit_name min(price)
-> from fruit;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'min(price)
from fruit' at line 1
mysql> select Fruit_name min(price)
-> from fruit;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'min(price)
from fruit' at line 1
mysql> SELECT Fruit_name, MIN(Price) AS Cheapest_Price
-> FROM FruitTable;
ERROR 1146 (42S02): Table 'poe.fruittable' doesn't exist
mysql> SELECT Fruit_name, MIN(Price) AS Cheapest_Price
-> FROM Fruit;
+------------+----------------+
| Fruit_name | Cheapest_Price |
+------------+----------------+
| mango | 15 |
+------------+----------------+
1 row in set (0.00 sec)
mysql> SELECT Fruit_name AS Name FROM FruitTable
-> UNION
-> SELECT Supplier_name AS Name FROM SupplierTable;
ERROR 1146 (42S02): Table 'poe.fruittable' doesn't exist
mysql> SELECT Fruit_name AS Name FROM Fruit
-> UNION
-> SELECT Supplier_name AS Name FROM SupplierTable;
+-----------------+
| Name |
+-----------------+
| mango |
| grapes |
| apple |
| maxi |
| marlin |
| FreshFruits |
| TropicalTreats |
| OrganicOrchards |
| JuicyJungle |
| FarmFresh |
+-----------------+
10 rows in set (0.00 sec)
mysql> SELECT DISTINCT s.Supplier_name
-> FROM SupplierTable s
-> JOIN FruitTable f ON s.Supplier_id = f.Supplier_id
-> WHERE f.Taste = 'Bitter';
ERROR 1146 (42S02): Table 'poe.fruittable' doesn't exist
mysql> SELECT DISTINCT s.Supplier_name
-> FROM SupplierTable s
-> JOIN Fruit f ON s.Supplier_id = f.Supplier_id
-> WHERE f.Taste = 'Bitter';
+---------------+
| Supplier_name |
+---------------+
| JuicyJungle |
| FarmFresh |
+---------------+
2 rows in set (0.00 sec)
mysql>