0% found this document useful (0 votes)
14 views13 pages

ASHWIN

mzka

Uploaded by

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

ASHWIN

mzka

Uploaded by

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

1. To create a database.

CODE:

CREATE DATABASE school;


OUTPUT:
Query OK, 1 row affected
(0.01 sec)
2. To create student table with student id ,
class, section,gender,name,DOB,
And marks as attributes where student id
is the primary key.
CODE:

CREATE TABLE Students (


student_id INT PRIMARY KEY,
class VARCHAR(10),
section CHAR(1),
gender CHAR(1),
name VARCHAR(100),
DOB DATE,
marks DECIMAL(5,2)
);
OUTPUT:
Query OK, 0 rows affected (0.04 sec)
3. To insert the details at least 10 student
in the above table.
CODE:
INSERT INTO Students (student_id, class, section, gender, name,
DOB, marks)

VALUES

(1, '10th', 'A', 'M', 'John Doe', '2007-05-15', 85.75),

(2, '10th', 'B', 'F', 'Jane Smith', '2007-08-22', 92.50),

(3, '9th', 'A', 'M', 'Michael Brown', '2008-12-03', 78.00),

(4, '11th', 'C', 'F', 'Emily Davis', '2006-11-14', 88.25),

(5, '12th', 'A', 'M', 'Daniel Wilson', '2005-04-30', 91.00),

(6, '10th', 'B', 'F', 'Sophia Martinez', '2007-07-21', 86.50),

(7, '11th', 'A', 'M', 'James Johnson', '2006-02-17', 79.75),

(8, '12th', 'C', 'F', 'Isabella Lee', '2005-09-11', 93.40),

(9, '9th', 'B', 'M', 'David Kim', '2008-03-29', 80.20),

(10, '10th', 'A', 'F', 'Olivia Garcia', '2007-10-06', 89.65);

OUTPUT:
Query OK, 10 rows affected (0.02 sec)
Records: 10 Duplicates: 0 Warnings: 0
4. To display the entire content of
table.
CODE:
SELECT * FROM Students;
OUTPUT:
+------------+-------+---------+--------+-----------------+------------+-------+

| student_id | class | section | gender | name | DOB | marks |

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

| 1 | 10th | A |M | John Doe | 2007-05-15 | 85.75 |

| 2 | 10th | B |F | Jane Smith | 2007-08-22 | 92.50 |

| 3 | 9th | A |M | Michael Brown | 2008-12-03 | 78.00 |

| 4 | 11th | C |F | Emily Davis | 2006-11-14 | 88.25 |

| 5 | 12th | A |M | Daniel Wilson | 2005-04-30 | 91.00 |

| 6 | 10th | B |F | Sophia Martinez | 2007-07-21 | 86.50 |

| 7 | 11th | A |M | James Johnson | 2006-02-17 | 79.75 |

| 8 | 12th | C |F | Isabella Lee | 2005-09-11 | 93.40 |

| 9 | 9th | B |M | David Kim | 2008-03-29 | 80.20 |

| 10 | 10th | A |F | Olivia Garcia | 2007-10-06 | 89.65 |

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

10 rows in set (0.01 sec)


5. Delete the details of a
student in the above
tables.
CODE:

DELETE FROM Students


WHERE student_id = 5;
OUTPUT:
-> WHERE student_id = 5;
Query OK, 1 row affected (0.01 sec)
6.To display Rno,name and marks of
those students who are scoring marks
more than 50.
CODE:
SELECT student_id, name, marks
FROM Students
WHERE marks > 50;
OUTPUT:
+------------+-----------------+-------+

| student_id | name | marks |

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

| 1 | John Doe | 85.75 |

| 2 | Jane Smith | 92.50 |

| 3 | Michael Brown | 78.00 |

| 4 | Emily Davis | 88.25 |

| 6 | Sophia Martinez | 86.50 |

| 7 | James Johnson | 79.75 |

| 8 | Isabella Lee | 93.40 |

| 9 | David Kim | 80.20 |

| 10 | Olivia Garcia | 89.65 |

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

9 rows in set (0.04 sec)


7. To display Rno,name andDOB of those
students who are born between 2005-01-
01 and 2005-12-31.
CODE:
SELECT student_id, name, DOB
-> FROM Students
-> WHERE DOB BETWEEN '2005-01-01'
AND '2005-12-31';
OUTPUT:
+------------+--------------+------------+
| student_id | name | DOB |
+------------+--------------+------------+
| 8 | Isabella Lee | 2005-09-11 |
+------------+--------------+------------+
1 row in set (0.00 sec)
8.Find the min,max,sum and average of the
marks in a student marks table.
CODE:
SELECT
-> MIN(marks) AS min_marks,
-> MAX(marks) AS max_marks,
-> SUM(marks) AS total_marks,
-> AVG(marks) AS average_marks
-> FROM Students;
OUTPUT:
+-----------+-----------+-------------+---------------+
| min_marks | max_marks | total_marks |
average_marks |
+-----------+-----------+-------------+---------------+
| 78.00 | 93.40 | 774.00 | 86.000000 |
+-----------+-----------+-------------+---------------+
1 row in set (0.01 sec)
9. Find the total number of customers from each
country in the table (customer ID , customer name,
country) using group by.
CODE:
CREATE TABLE Customers (
-> customer_id INT PRIMARY KEY,
-> customer_name VARCHAR(100),
-> country VARCHAR(50)
-> );
Query OK, 0 rows affected (0.04 sec)
INSERT INTO Customers (customer_id,
customer_name, country)
-> VALUES
-> (1, 'Alice Johnson', 'USA'),
-> (2, 'Bob Smith', 'Canada'),
-> (3, 'Carlos Hernandez', 'Mexico'),
-> (4, 'Diana Wang', 'China'),
-> (5, 'Eva Müller', 'Germany');
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0

SELECT country, COUNT(customer_id) AS


total_customers
-> FROM Customers
-> GROUP BY country;
OUTPUT:
+---------+-----------------+
| country | total_customers |
+---------+-----------------+
| USA | 1|
| Canada | 1|
| Mexico | 1|
| China | 1|
| Germany | 1|
+---------+-----------------+
5 rows in set (0.01 sec)
10. Write a Sql query to order the ( student Id ,
marks) table in descending order of the marks.
CODE:
SELECT student_id, marks
-> FROM Students
-> ORDER BY marks DESC;

OUTPUT:
+------------+-------+

| student_id | marks |

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

| 8 | 93.40 |

| 2 | 92.50 |

| 10 | 89.65 |

| 4 | 88.25 |

| 6 | 86.50 |

| 1 | 85.75 |

| 9 | 80.20 |

| 7 | 79.75 |

| 3 | 78.00 |

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

9 rows in set (0.00 sec)

You might also like