Advanced_SQL_QnA_With_Answers
Advanced_SQL_QnA_With_Answers
Q: Create a table Employee with constraints: eid as primary key, email as unique, salary as
NOT NULL.
name VARCHAR(50),
);
Q: Alter the table to add a department column with default value 'HR'.
A: -- Note: MySQL doesn't support dropping named constraints easily unless you name them.
A: SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
Q: Find names that end with 'a' and start with 'R'.
Q: Calculate how many days are left until the exam (use CURDATE()).
Q: List students who scored more than the average marks of age 20 group.
);
Q: Find students who have the exact same marks as someone else.
WHERE EXISTS (
Q: Get student(s) who have highest age among those who scored above 80.
WHERE age = (
);
FROM Student s
LIMIT 1;
A: SELECT id,
CASE
ELSE 'Poor'
END AS feedback
FROM Feedback;
Q: Count how many students passed and failed using GROUP BY.
A: SELECT
CASE WHEN marks >= 40 THEN 'Pass' ELSE 'Fail' END AS status,
COUNT(*) AS count
FROM Student
GROUP BY status;