0% found this document useful (0 votes)
11 views2 pages

Students Table SQL All Queries

The document provides SQL queries for managing a 'students' table, including creating the table, inserting records, and performing select, update, and delete operations. It also covers aggregate functions, ordering and grouping results, and grading students based on their marks using a CASE statement. Overall, it serves as a comprehensive guide for executing various SQL queries related to student data management.

Uploaded by

chettenparkash13
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)
11 views2 pages

Students Table SQL All Queries

The document provides SQL queries for managing a 'students' table, including creating the table, inserting records, and performing select, update, and delete operations. It also covers aggregate functions, ordering and grouping results, and grading students based on their marks using a CASE statement. Overall, it serves as a comprehensive guide for executing various SQL queries related to student data management.

Uploaded by

chettenparkash13
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

Students Table – SQL All Queries

1. Create Table
CREATE TABLE students (
student_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
age INT,
gender VARCHAR(10),
department VARCHAR(50),
marks INT,
admission_date DATE
);

2. Insert Records
INSERT INTO students VALUES
(1, 'Ali', 20, 'Male', 'Computer Science', 85, '2024-01-10'),
(2, 'Sara', 21, 'Female', 'IT', 90, '2024-01-12'),
(3, 'Ahmed', 19, 'Male', 'Computer Science', 78, '2024-01-15'),
(4, 'Ayesha', 22, 'Female', 'Software Engineering', 88, '2024-01-18');

3. Select Queries
SELECT * FROM students;
SELECT name, department, marks FROM students;
SELECT * FROM students WHERE marks > 80;

4. Update Query
UPDATE students SET marks = 92 WHERE student_id = 2;

5. Delete Query
DELETE FROM students WHERE student_id = 3;

6. Aggregate Functions
SELECT COUNT(*) FROM students;
SELECT AVG(marks) FROM students;
SELECT MAX(marks), MIN(marks) FROM students;

7. Order & Group


SELECT * FROM students ORDER BY marks DESC;
SELECT department, COUNT(*) FROM students GROUP BY department;

8. Grade Using CASE


SELECT name, marks,
CASE
WHEN marks >= 90 THEN 'A'
WHEN marks >= 80 THEN 'B'
WHEN marks >= 70 THEN 'C'
ELSE 'Fail'
END AS grade
FROM students;

You might also like