{"id":2898,"date":"2025-12-08T04:15:52","date_gmt":"2025-12-08T04:15:52","guid":{"rendered":"https:\/\/codeinsightacademy.com\/blog\/?p=2898"},"modified":"2026-01-21T09:20:17","modified_gmt":"2026-01-21T09:20:17","slug":"sql-assignment","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/sql\/sql-assignment\/","title":{"rendered":"SQL Assignment"},"content":{"rendered":"\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>id<\/th><th>name<\/th><th>department<\/th><th>manager_id<\/th><th>salary<\/th><th>city<\/th><th>created_at<\/th><th>updated_at<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Amit Sharma<\/td><td>Sales<\/td><td>NULL<\/td><td>75000<\/td><td>Mumbai<\/td><td>2023-01-10<\/td><td>2023-06-01<\/td><\/tr><tr><td>2<\/td><td>Priya Patel<\/td><td>Marketing<\/td><td>1<\/td><td>68000<\/td><td>Ahmedabad<\/td><td>2023-02-15<\/td><td>2023-05-18<\/td><\/tr><tr><td>3<\/td><td>Rahul Singh<\/td><td>IT<\/td><td>1<\/td><td>92000<\/td><td>Bengaluru<\/td><td>2023-03-05<\/td><td>2023-04-22<\/td><\/tr><tr><td>4<\/td><td>Neha Gupta<\/td><td>HR<\/td><td>2<\/td><td>61000<\/td><td>Delhi<\/td><td>2023-04-20<\/td><td>2023-05-30<\/td><\/tr><tr><td>5<\/td><td>Karan Verma<\/td><td>IT<\/td><td>3<\/td><td>88000<\/td><td>Pune<\/td><td>2023-05-09<\/td><td>2023-06-10<\/td><\/tr><tr><td>6<\/td><td>Sneha Roy<\/td><td>Sales<\/td><td>1<\/td><td>74000<\/td><td>Kolkata<\/td><td>2023-02-11<\/td><td>2023-05-25<\/td><\/tr><tr><td>7<\/td><td>Rohan Mehta<\/td><td>Marketing<\/td><td>2<\/td><td>70000<\/td><td>Mumbai<\/td><td>2023-03-22<\/td><td>2023-05-17<\/td><\/tr><tr><td>8<\/td><td>Anjali Rao<\/td><td>IT<\/td><td>3<\/td><td>93000<\/td><td>Hyderabad<\/td><td>2023-04-15<\/td><td>2023-06-05<\/td><\/tr><\/tbody><\/table><figcaption>table: employees<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2>BASIC SELECT (FOUNDATION)<\/h2>\n\n\n\n<h3>1. Display all employees in <strong>descending order of salary<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>2. Display all employees who belong to <strong>Mumbai city<\/strong>.<br><em>(Assume city is stored inside department or via mapping \u2014 students must clarify)<\/em><\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>3. Find all employees whose <strong>salary is more than the average salary<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>4. Display the <strong>total sum of salary<\/strong> of all employees.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>5. Display all <strong>unique employee addresses<\/strong>.<br><em>(If address column is not available, students must modify table)<\/em><\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>6. Display a column called <strong>details<\/strong> that shows:<br><strong>name + address concatenated<\/strong>, along with salary.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2>INTERMEDIATE AGGREGATION &amp; FILTERING<\/h2>\n\n\n\n<h3>7. Display the <strong>name(s) of employee(s) having the maximum salary<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>8. Find the <strong>employee(s) having the second highest salary<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>9. Display the <strong>count of employees by address<\/strong>, ordered by employee count.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>10. Show the <strong>total number of employees from Nagpur only<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>11. Display employees whose <strong>names start OR end with a vowel (a,e,i,o,u)<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>12. Find the <strong>employee(s) having maximum salary in each city<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>13. Display the <strong>top 5 highest salaried employees<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>14. Display the <strong>second highest salaried employee using a subquery<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>15. Show the <strong>list of cities where total salary is more than 200000<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2> JOINS BASED ASSIGNMENTS (STUDENT SYSTEM)<\/h2>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>id<\/th><th>name<\/th><th>city<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Rahul Kumar<\/td><td>Patna<\/td><\/tr><tr><td>2<\/td><td>Meera Nair<\/td><td>Chennai<\/td><\/tr><tr><td>3<\/td><td>Ayesha Khan<\/td><td>Lucknow<\/td><\/tr><tr><td>4<\/td><td>Arjun Das<\/td><td>Kolkata<\/td><\/tr><tr><td>5<\/td><td>Sanya Singh<\/td><td>Jaipur<\/td><\/tr><\/tbody><\/table><figcaption>table: students<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>id<\/th><th>name<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Mathematics<\/td><\/tr><tr><td>2<\/td><td>Science<\/td><\/tr><tr><td>3<\/td><td>English<\/td><\/tr><tr><td>4<\/td><td>Computer Science<\/td><\/tr><\/tbody><\/table><figcaption>table: subject_master<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>id<\/th><th>student_id<\/th><th>department_id<\/th><th>marks<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>1<\/td><td>1<\/td><td>85<\/td><\/tr><tr><td>2<\/td><td>1<\/td><td>4<\/td><td>78<\/td><\/tr><tr><td>3<\/td><td>2<\/td><td>2<\/td><td>82<\/td><\/tr><tr><td>4<\/td><td>2<\/td><td>3<\/td><td>90<\/td><\/tr><tr><td>5<\/td><td>3<\/td><td>1<\/td><td>75<\/td><\/tr><tr><td>6<\/td><td>3<\/td><td>3<\/td><td>80<\/td><\/tr><tr><td>7<\/td><td>4<\/td><td>4<\/td><td>95<\/td><\/tr><tr><td>8<\/td><td>5<\/td><td>2<\/td><td>88<\/td><\/tr><\/tbody><\/table><figcaption>table: result<\/figcaption><\/figure>\n\n\n\n<h3>16. Display <strong>all students who have appeared for the exam<\/strong>.<br><em>(Students who exist in result table)<\/em><\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>17. Display:<br><strong>Student Name, Subject (Department Name), and Marks<\/strong><\/h3>\n\n\n\n<p>Using:<\/p>\n\n\n\n<ul><li>students<\/li><li>departments<\/li><li>result<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>18. Display <strong>Student Name and Total Marks<\/strong> only for students whose<br><strong>total marks are greater than 80<\/strong>.<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2>TRIGGERS &amp; EVENTS (ADVANCED)<\/h2>\n\n\n\n<h3>19. (Trigger Assignment)<\/h3>\n\n\n\n<p>Create a <strong>trigger<\/strong> such that:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><strong>Whenever an employee is deleted, their data is automatically inserted into <code>deleted_employees<\/code> table.<\/strong><\/p><\/blockquote>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3>20. (Event Scheduler Assignment)<\/h3>\n\n\n\n<p>Create a <strong>MySQL event<\/strong> that:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>Automatically <strong>deletes audit logs older than 5 minutes<\/strong>, and<br>Runs <strong>every 2 minutes<\/strong>.<\/p><\/blockquote>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h1>CHALLENGE<\/h1>\n\n\n\n<ul><li>Find employees who <strong>do not have a manager<\/strong><\/li><li>Find departments having <strong>more than 5 employees<\/strong><\/li><li>Show <strong>manager name with employee name<\/strong> (self join)<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h1>TABLES<\/h1>\n\n\n\n<h3>\ud83d\udd39 employee<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>id, name, department, manager_id, salary, created_at, updated_at\n<\/code><\/pre>\n\n\n\n<h3>\ud83d\udd39 students<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>id, name\n<\/code><\/pre>\n\n\n\n<h3>\ud83d\udd39 department<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>id, name\n<\/code><\/pre>\n\n\n\n<h3>\ud83d\udd39 result<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>id, student_id, department_id, marks\n<\/code><\/pre>\n\n\n\n<h3>\ud83d\udd39 auditlog<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>id, username, activity, created_at\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>id name department manager_id salary city created_at updated_at 1 Amit Sharma Sales NULL 75000 Mumbai 2023-01-10 2023-06-01 2 Priya Patel Marketing 1 68000 Ahmedabad 2023-02-15 2023-05-18 3 Rahul Singh IT 1 92000 Bengaluru 2023-03-05 2023-04-22 4 Neha Gupta HR 2 61000 Delhi 2023-04-20 2023-05-30 5 Karan Verma IT 3 88000 Pune 2023-05-09 2023-06-10 6 Sneha [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[34],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2898"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=2898"}],"version-history":[{"count":10,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2898\/revisions"}],"predecessor-version":[{"id":2934,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2898\/revisions\/2934"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=2898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=2898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=2898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}