{"id":27455521,"url":"https://github.com/smykhailevskyi/sql_leetcode","last_synced_at":"2026-05-02T02:36:42.399Z","repository":{"id":287744768,"uuid":"965647640","full_name":"smykhailevskyi/sql_leetcode","owner":"smykhailevskyi","description":"Leetcode SQL questions for the interview preparations","archived":false,"fork":false,"pushed_at":"2025-04-13T16:56:35.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T17:43:23.626Z","etag":null,"topics":["database","interview","interview-practice","interview-preparations","leetcode","postgresql","sql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smykhailevskyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-13T16:10:34.000Z","updated_at":"2025-04-13T16:56:38.000Z","dependencies_parsed_at":"2025-04-13T17:43:27.053Z","dependency_job_id":"2431a074-0c5d-48f5-8785-27f974e07814","html_url":"https://github.com/smykhailevskyi/sql_leetcode","commit_stats":null,"previous_names":["smykhailevskyi/sql_leetcode"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smykhailevskyi%2Fsql_leetcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smykhailevskyi%2Fsql_leetcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smykhailevskyi%2Fsql_leetcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smykhailevskyi%2Fsql_leetcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smykhailevskyi","download_url":"https://codeload.github.com/smykhailevskyi/sql_leetcode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249110783,"owners_count":21214400,"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":["database","interview","interview-practice","interview-preparations","leetcode","postgresql","sql"],"created_at":"2025-04-15T16:43:55.104Z","updated_at":"2026-05-02T02:36:42.388Z","avatar_url":"https://github.com/smykhailevskyi.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Leetcode 50 SQL questions](https://leetcode.com/studyplan/top-sql-50/)\n\n\u003e :exclamation: All queries are statements for **PostgreSQL** database. \n\n* [Select](#select)  \n* [Basic Joins](#basic-joins)\n\n### Select\n\n#### 1757 Recyclable and low fat products\n:point_right: https://leetcode.com/problems/recyclable-and-low-fat-products/description/\n```\nSELECT product_id \nFROM products\nWHERE low_fats = 'Y' AND recyclable = 'Y';\n```\n\n#### 584 Find customer referee\n:point_right: https://leetcode.com/problems/find-customer-referee/description/\n```\nSELECT name\nFROM customer\nWHERE customer.referee_id \u003c\u003e 2;\n```\n❗ From PostgreSQL documentation:  \n\u003c\u003e is the standard SQL notation for “not equal”. != is an alias, which is converted to \u003c\u003e at a very early stage of parsing. Hence, it is not possible to implement != and \u003c\u003e operators that do different things.\n\n#### 595 Big countries\n:point_right: https://leetcode.com/problems/big-countries/description/\n```\nSELECT name, population, area\nFROM world\nWHERE area \u003e= 3000000 OR population \u003e= 25000000;\n```\n\n#### 1148 Article views I\n:point_right: https://leetcode.com/problems/article-views-i/description/\n```\nSELECT DISTINCT ON (author_id) author_id AS id\nFROM views\nWHERE author_id = viewer_id;\n```\n\n#### 1683 Invalid tweets\n:point_right: https://leetcode.com/problems/invalid-tweets/description/\n```\nSELECT tweet_id\nFROM tweets\nWHERE length(content) \u003e 15;\n```\n\n### Basic Joins\n\n#### 1378 Replace employee Id with the unique identifier  \n:point_right: https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/description  \n\n:exclamation: A table order in the FROM clause is important.\n\n* **RIGHT JOIN**  \n  ```\n  SELECT name, unique_id \n  FROM employeeUNI \n  RIGHT JOIN employees ON employeeUNI.id = employees.id;\n  ```\n* **LEFT JOIN**\n  ```\n  SELECT name, unique_id\n  FROM employees \n  LEFT JOIN employeeUNI ON employeeUNI.id = employees.id;\n  ```\n\n#### 1068 Product sales analisys I  \n:point_right: https://leetcode.com/problems/product-sales-analysis-i/description  \n\n**INNER JOIN**\n```\nSELECT product_name, year, price\nFROM Sales\nJOIN product ON sales.product_id = product.product_id;\n```\n\n#### 1581 Customer who visited but did not make any transactions   \n:point_right: https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/  \n\n**LEFT JOIN**, **GROUP BY**, **COUNT**\n```\nSELECT v.customer_id, COUNT(*) AS count_no_trans\nFROM visits v\nLEFT JOIN transactions t\nON v.visit_id = t.visit_id\nWHERE t.transaction_id IS NULL \nGROUP BY v.customer_id;\n```\n\n#### 197 Rising temperature   \n:point_right: https://leetcode.com/problems/rising-temperature/description/\n\n**INNER JOIN**, **INTERVAL**\n\n❗ Data/Time functions and operators in PostgreSQL documentation: https://www.postgresql.org/docs/current/functions-datetime.html\n\n```\nSELECT w1.id\nFROM weather w1\nJOIN weather w2 ON w1.recordDate = w2.recordDate + INTERVAL '1 DAY'\nWHERE w1.temperature \u003e w2.temperature;\n```\n\n#### 1661 Average time of process per machine   \n:point_right: https://leetcode.com/problems/average-time-of-process-per-machine/description/\n\n**INNER JOIN**, **ROUND**, **AVG**, **CAST**, **GROUP BY**\n\n```\nSELECT a.machine_id, ROUND(AVG(CAST(b.timestamp - a.timestamp AS DECIMAL)), 3) AS processing_time\nFROM activity a\nJOIN activity b ON a.machine_id = b.machine_id AND a.process_id = b.process_id AND a.activity_type = 'start' AND b.activity_type = 'end'\nGROUP BY a.machine_id;\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmykhailevskyi%2Fsql_leetcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmykhailevskyi%2Fsql_leetcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmykhailevskyi%2Fsql_leetcode/lists"}