{"id":28089252,"url":"https://github.com/manojvermadatabase/sql_interview","last_synced_at":"2026-02-27T19:44:52.283Z","repository":{"id":288566201,"uuid":"968521462","full_name":"manojvermadatabase/SQL_INTERVIEW","owner":"manojvermadatabase","description":"PRACTICE SET FOR INTERVIEW","archived":false,"fork":false,"pushed_at":"2025-04-30T17:40:19.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T18:39:28.298Z","etag":null,"topics":["sql-server"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manojvermadatabase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-18T08:24:04.000Z","updated_at":"2025-04-30T17:40:24.000Z","dependencies_parsed_at":"2025-04-24T02:38:09.055Z","dependency_job_id":null,"html_url":"https://github.com/manojvermadatabase/SQL_INTERVIEW","commit_stats":null,"previous_names":["mg459236/sql_interview","manojvermadatabase/sql_interview"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojvermadatabase%2FSQL_INTERVIEW","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojvermadatabase%2FSQL_INTERVIEW/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojvermadatabase%2FSQL_INTERVIEW/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojvermadatabase%2FSQL_INTERVIEW/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manojvermadatabase","download_url":"https://codeload.github.com/manojvermadatabase/SQL_INTERVIEW/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253948333,"owners_count":21988953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sql-server"],"created_at":"2025-05-13T12:55:35.520Z","updated_at":"2026-02-27T19:44:52.252Z","avatar_url":"https://github.com/manojvermadatabase.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"The SQL Developer Interview Guide is a comprehensive resource designed to help candidates prepare for interviews related to SQL development roles. It covers essential topics such as SQL queries, database design, normalization, indexing, stored procedures, performance tuning, and real-world problem-solving scenarios. This guide also includes frequently asked interview questions, best practices, and tips to showcase your SQL skills confidently. Whether you're a beginner or an experienced developer, this guide equips you with the knowledge and strategies to succeed in your next interview.\n\n## //Average Time of Process per Machine//\nTable: Activity\n```\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| machine_id     | int     |\n| process_id     | int     |\n| activity_type  | enum    |\n| timestamp      | float   |\n+----------------+---------+\n```\nThe table shows the user activities for a factory website.\n(machine_id, process_id, activity_type) is the primary key (combination of columns with unique values) of this table.\nmachine_id is the ID of a machine.\nprocess_id is the ID of a process running on the machine with ID machine_id.\nactivity_type is an ENUM (category) of type ('start', 'end').\ntimestamp is a float representing the current time in seconds.\n'start' means the machine starts the process at the given timestamp and 'end' means the machine ends the process at the given timestamp.\nThe 'start' timestamp will always be before the 'end' timestamp for every (machine_id, process_id) pair.\nIt is guaranteed that each (machine_id, process_id) pair has a 'start' and 'end' timestamp.\n \n\nThere is a factory website that has several machines each running the same number of processes. Write a solution to find the average time each machine takes to complete a process.\n\nThe time to complete a process is the 'end' timestamp minus the 'start' timestamp. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.\n\nThe resulting table should have the machine_id along with the average time as processing_time, which should be rounded to 3 decimal places.\n\nReturn the result table in any order.\n\nThe result format is in the following example.\n\n \n```\nExample 1:\n\nInput: \nActivity table:\n+------------+------------+---------------+-----------+\n| machine_id | process_id | activity_type | timestamp |\n+------------+------------+---------------+-----------+\n| 0          | 0          | start         | 0.712     |\n| 0          | 0          | end           | 1.520     |\n| 0          | 1          | start         | 3.140     |\n| 0          | 1          | end           | 4.120     |\n| 1          | 0          | start         | 0.550     |\n| 1          | 0          | end           | 1.550     |\n| 1          | 1          | start         | 0.430     |\n| 1          | 1          | end           | 1.420     |\n| 2          | 0          | start         | 4.100     |\n| 2          | 0          | end           | 4.512     |\n| 2          | 1          | start         | 2.500     |\n| 2          | 1          | end           | 5.000     |\n+------------+------------+---------------+-----------+\nOutput: \n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0          | 0.894           |\n| 1          | 0.995           |\n| 2          | 1.456           |\n+------------+-----------------+\n```\nExplanation:\nThere are 3 machines running 2 processes each.\nMachine 0's average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894\nMachine 1's average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995\nMachine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456\n ##  SOLUTION OF Average Time of Process per Machine\n```sql\nSELECT \n    machine_id,\n    ROUND(AVG(end_time - start_time), 3) AS processing_time\nFROM (\n    SELECT \n        a.machine_id,\n        a.process_id,\n        MAX(CASE WHEN a.activity_type = 'start' THEN a.timestamp END) AS start_time,\n        MAX(CASE WHEN a.activity_type = 'end' THEN a.timestamp END) AS end_time\n    FROM \n        Activity a\n    GROUP BY \n        a.machine_id, a.process_id\n) AS subquery\nGROUP BY \n    machine_id;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanojvermadatabase%2Fsql_interview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanojvermadatabase%2Fsql_interview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanojvermadatabase%2Fsql_interview/lists"}