এই Lisson এ SQL Aggregate functions SUM(), AVG(), COUNT(), MAX(), MIN(), Order By, Join Query এর ব্যবহার দেখব।
Aggregate Functions:
SELECT MIN(age)
FROM students;
SELECT MAX(age)
FROM students;
SELECT COUNT(age)
FROM students;
SELECT AVG(age)
FROM students;
SELECT SUM(age)
FROM students;
SELECT * FROM students
WHERE age = (SELECT MAX(age) FROM students)
Group By:
SELECT class, COUNT(id)
FROM students
GROUP BY class;
SELECT class, MAX(age) AS student_age
FROM students
GROUP BY class;
Union:
SELECT id, name
FROM students
WHERE age = 21
UNION
SELECT id, name
FROM students
WHERE age = 12;
Join Query:
SELECT * FROM students
JOIN classes ON classes.id = students.class_id;
SELECT * FROM students
INNER JOIN classes ON classes.id = students.class_id;
SELECT * FROM students
LEFT JOIN classes ON classes.id = students.class_id;
SELECT * FROM students
RIGHT JOIN classes ON classes.id = students.class_id;
SELECT * FROM students
LEFT JOIN classes ON classes.id = students.class_id
UNION
SELECT * FROM students
RIGHT JOIN classes ON classes.id = students.class_id;
SELECT * FROM students
LEFT JOIN classes ON classes.id = students.class_id
UNION ALL
SELECT * FROM students
RIGHT JOIN classes ON classes.id = students.class_id;