├── P4.md ├── P3.md ├── P6.md ├── P1.md ├── P2.md ├── P5.md └── README.md /P4.md: -------------------------------------------------------------------------------- 1 | Given a table called "bugs" with the following columns (id, token, title, category, device, reported_at, created_at, updated_at). 2 | Select all distinct bug categories. 3 | 4 | ```SELECT DISTINCT category FROM bugs``` 5 | -------------------------------------------------------------------------------- /P3.md: -------------------------------------------------------------------------------- 1 | P3. For the same tables in P1, get the name of the most popular course (the one where the most students are enrolled) and if there is a tie, get the course that's lexicographically the smallest 2 | ``` 3 | SELECT c.name 4 | FROM courses c 5 | INNER JOIN grades g ON g.course_id = c.id 6 | GROUP BY c.id, c.name 7 | ORDER BY COUNT(*) DESC, c.name 8 | LIMIT 1; 9 | ``` 10 | -------------------------------------------------------------------------------- /P6.md: -------------------------------------------------------------------------------- 1 | P6. For the same table in P4, find the title of the bug with token = "token660" and reported_at on "2020-08-30". 2 | This problem is graded partially, 10% on correctness (your query gets the correct count) and 90% on performance (your query makes use of available indexes). 3 | 4 | ***Scored 10% only*** 5 | ``` 6 | SELECT x.title FROM bugs 7 | AS y USE INDEX (index_bugs_on_category_and_token_and_reported_at) 8 | JOIN bugs AS x ON x.id=y.id 9 | WHERE y.token ='token660' AND y.reported_at = '2020-08-30' 10 | ``` 11 | 12 | -------------------------------------------------------------------------------- /P1.md: -------------------------------------------------------------------------------- 1 | P1. Given 3 tables, students(id, name) , courses(id, name) , grades(id, course_id, student_id, grade), 2 | 3 | find the top 100 students based on their 4 | 5 | average grades sorted descendingly by the average grade and in case multiple students have the same average grade, 6 | sort them lexicographically in ascending order by their names. 7 | 8 | Your query should output a table with the following columns (name, average_grade).Submission endpoint: 9 | ``` 10 | SELECT DISTINCT students.name AS name, avg(grade) AS average_grade FROM grades 11 | RIGHT JOIN students ON students.id = grades.student_id 12 | GROUP BY students.name 13 | ORDER BY avg(grade) DESC, students.name ASC 14 | LIMIT 100 15 | ``` 16 | -------------------------------------------------------------------------------- /P2.md: -------------------------------------------------------------------------------- 1 | For the same tables in P1, for each student, get all the courses that he/she is enrolled in along with the grade he/she scored for each course. 2 | Order the result by the student name in ascending order and if there is a tie, break it with the course name in ascending order and 3 | if there is a tie break it with the grade in ascending order. The final result should have 3 columns with names (name, course, grade). 4 | Submission endpoint: 5 | ``` 6 | SELECT DISTINCT students.name AS name,courses.name AS course, grades.grade AS grade 7 | FROM ((grades 8 | INNER JOIN students ON students.id = grades.student_id 9 | INNER JOIN courses ON courses.id = grades.course_id)) 10 | ORDER BY students.name ASC, courses.name ASC, grades.grade ASC 11 | ``` 12 | -------------------------------------------------------------------------------- /P5.md: -------------------------------------------------------------------------------- 1 | P5. For the same table in P4, find how many bugs were created on "2019-03-01" or later. Your query should produce a table with one column called "count". 2 | This problem is graded partially, 10% on correctness (your query gets the correct count) and 90% on performance (your query makes use of available indexes). 3 | 4 | ***Scored 10% only*** 5 | 6 | `SHOW INDEXES FROM bugs;` 7 | 8 | ``` 9 | "records": [ 10 | { 11 | "Table": "bugs", 12 | "Non_unique": 0, 13 | "Key_name": "PRIMARY", 14 | "Seq_in_index": 1, 15 | "Column_name": "id", 16 | "Collation": "A", 17 | "Cardinality": 9791826, 18 | "Sub_part": null, 19 | "Packed": null, 20 | "Null": "", 21 | "Index_type": "BTREE", 22 | "Comment": "", 23 | "Index_comment": "" 24 | }, 25 | { 26 | "Table": "bugs", 27 | "Non_unique": 1, 28 | "Key_name": "index_bugs_on_category_and_token_and_reported_at", 29 | "Seq_in_index": 1, 30 | "Column_name": "category", 31 | "Collation": "A", 32 | "Cardinality": 1, 33 | "Sub_part": null, 34 | "Packed": null, 35 | "Null": "YES", 36 | "Index_type": "BTREE", 37 | "Comment": "", 38 | "Index_comment": "" 39 | }, 40 | { 41 | "Table": "bugs", 42 | "Non_unique": 1, 43 | "Key_name": "index_bugs_on_category_and_token_and_reported_at", 44 | "Seq_in_index": 2, 45 | "Column_name": "token", 46 | "Collation": "A", 47 | "Cardinality": 29946, 48 | "Sub_part": null, 49 | "Packed": null, 50 | "Null": "YES", 51 | "Index_type": "BTREE", 52 | "Comment": "", 53 | "Index_comment": "" 54 | }, 55 | { 56 | "Table": "bugs", 57 | "Non_unique": 1, 58 | "Key_name": "index_bugs_on_category_and_token_and_reported_at", 59 | "Seq_in_index": 3, 60 | "Column_name": "reported_at", 61 | "Collation": "A", 62 | "Cardinality": 6085027, 63 | "Sub_part": null, 64 | "Packed": null, 65 | "Null": "YES", 66 | "Index_type": "BTREE", 67 | "Comment": "", 68 | "Index_comment": "" 69 | } 70 | ] 71 | } 72 | ``` 73 | ``` 74 | SELECT COUNT(x.created_at) AS count 75 | FROM bugs AS y 76 | USE INDEX (PRIMARY,index_bugs_on_category_and_token_and_reported_at) 77 | INNER JOIN bugs AS x ON x.id=y.id 78 | WHERE x.created_at >= '2019-03-01 79 | ``` 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## NOTE: SOME ANSWERS ARE NOT CORRECT! PLEASE DO NOT CONSIDER IT AS A SOURCE OF TRUTH, I CREATED THIS REPO TO TRACK THE PROGRESS DURING THE PROCESS ONLY. 2 | 3 | # Instabug-BE-Technical-Task 4 | Instabug Backend Internship Summer 2022 Technical Task 5 | 6 | ***Received my rejection letter in 06/06/2022. Sad, but atleast we are one rejection closer to an offer!*** 7 | 8 | It consists of six MySQL questions where we had to run POST requests on their API endpoint 9 | to execute the problems' queries and submit the solution. 10 | 11 | | Question No. | Complexity | Wrong Attempts No. | Requirements | Time of Submission MM/DD/YYYY HH:MM:SS | My comments | 12 | |--------------|------------|----------------------------------------------------------|-------------------------|----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| 13 | | 1 | Easy | 4-5 (First question to answer so didn't know the system) | Basic SQL | 06/01/2022 10:26:18 PM | I hope I'll not lose marks because I submitted wrong table names instead :@@@@@@ | 14 | | 2 | Medium | 2 | Basic SQL | 06/01/2022 10:32:05 PM | Normal one I believe | 15 | | 3 | Hard | 1 | Some Advanced Queries | 06/02/2022 2:09:54 AM | The server kept respond with Killing Query I thought they wanted a more efficient query But later then they mentioned that it is normal, and it was too late.... | 16 | | 4 | Easy | 0 | Basic SQL | 06/02/2022 9:50:54 AM | Nothing, just a normal distinct question | 17 | | 5 | Hard | 2 | Advanced SQL (Indexing) | 06/02/2022 4:54:41 PM | I HATE THIS PROBLEM AND 6 AS WELL | 18 | | 6 | Medium | 1 | Advanced SQL (Indexing) | 06/02/2022 3:34:47 PM | I DON'T KNOW HOW CAN I IMPROVE THE EFFICIENCY OF INDEXED QUERIES | 19 | 20 | ## My comments 21 | 22 | Regarding this experience, I enjoyed it kind of. Yet it could have been better if it they have mentioned earlier some details like we could have submitted queries once more, and that Killing query issue is not a big deal. 23 | 24 | ***Note: Check each file's history*** 25 | --------------------------------------------------------------------------------