{"id":25268197,"url":"https://github.com/alokshandilya/sql50-leetcode","last_synced_at":"2025-06-27T23:36:24.419Z","repository":{"id":277102742,"uuid":"931330527","full_name":"alokshandilya/sql50-leetcode","owner":"alokshandilya","description":"SQL 50 leetcode | solutions | postgres ","archived":false,"fork":false,"pushed_at":"2025-03-03T07:03:16.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T04:19:24.915Z","etag":null,"topics":["leetcode","postgresql","sql","sql50"],"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/alokshandilya.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}},"created_at":"2025-02-12T05:04:18.000Z","updated_at":"2025-03-03T07:03:19.000Z","dependencies_parsed_at":"2025-02-12T06:44:43.997Z","dependency_job_id":"4981f111-d4c9-4956-a5ec-903b0a801bb2","html_url":"https://github.com/alokshandilya/sql50-leetcode","commit_stats":null,"previous_names":["alokshandilya/sql50-leetcode"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alokshandilya/sql50-leetcode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alokshandilya%2Fsql50-leetcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alokshandilya%2Fsql50-leetcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alokshandilya%2Fsql50-leetcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alokshandilya%2Fsql50-leetcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alokshandilya","download_url":"https://codeload.github.com/alokshandilya/sql50-leetcode/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alokshandilya%2Fsql50-leetcode/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262352129,"owners_count":23297642,"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":["leetcode","postgresql","sql","sql50"],"created_at":"2025-02-12T10:24:16.443Z","updated_at":"2025-06-27T23:36:24.372Z","avatar_url":"https://github.com/alokshandilya.png","language":null,"readme":"# Top SQL 50 Study Plan (LeetCode)\n\nThis repository contains solutions to the **Top SQL 50 Study Plan** from [LeetCode](https://leetcode.com/studyplan/top-sql-50/) using **PostgreSQL**. Each problem is linked to its corresponding LeetCode page, and solutions are provided in PostgreSQL syntax.\n\n## Order of Execution\n\n\u003cp align=\"center\"\u003e\n    \u003cimg height=\"300px\" src=\"https://github.com/user-attachments/assets/d87d4980-2c19-492e-85b1-56ed449ea3d4\"\u003e\n\u003c/p\u003e\n\n## Select\n\n#### 1. [Recyclable and Low Fat Products (1757)](https://leetcode.com/problems/recyclable-and-low-fat-products/)\n\n```sql\nSELECT\n    product_id\nFROM\n    Products\nWHERE\n    low_fats = 'Y'\n    AND\n    recyclable = 'Y';\n```\n\n#### 2. [Find Customer Referee (584)](https://leetcode.com/problems/find-customer-referee/)\n\n```sql\nSELECT\n    name\nFROM\n    Customer\nWHERE\n    referee_id \u003c\u003e 2\n    OR\n    referee_id IS NULL;\n```\n\n\u003e **NOTE:** The `\u003c\u003e`, `!=` operator is used to compare two values and return `TRUE` if they are not equal, and `FALSE` otherwise.\n\u003e\n\u003e ```sql\n\u003e SELECT\n\u003e     NULL \u003c\u003e 2\n\u003e         AS result;\n\u003e\n\u003e -- output: NULL\n\u003e ```\n\n#### 3. [Big Countries (595)](https://leetcode.com/problems/big-countries/)\n\n```sql\nSELECT\n    name,\n    population,\n    area\nFROM\n    World\nWHERE\n    area \u003e= 3000000\n    OR\n    population \u003e= 25000000;\n```\n\n#### 4. [Article Views I (1148)](https://leetcode.com/problems/article-views-i/)\n\n```sql\nSELECT\n    DISTINCT\n        author_id AS id\nFROM\n    Views\nWHERE\n    author_id = viewer_id\nORDER BY\n    id;  -- or 1 (1st selected column) author_id/id)\n```\n\n#### 5. [Invalid Tweets (1683)](https://leetcode.com/problems/invalid-tweets/)\n\n```sql\nSELECT\n    tweet_id\nFROM\n    Tweets\nWHERE\n    LENGTH(content) \u003e 15;\n```\n\n\u003e [PostgreSQL string functions](https://www.postgresql.org/docs/current/functions-string.html) docs  \n\u003e The `LENGTH()` function returns the length of a string in characters.\n\u003e\n\u003e ```\n\u003e  length (text) → integer\n\u003e      Returns the number of characters in the string.\n\u003e      length('jose') → 4\n\u003e ```\n\n## Basic Joins\n\n\u003e JOINs are used to combine rows from two or more tables based on a related column between them.\n\u003e\n\u003e - [Neon docs | PostgreSQL Joins](https://neon.tech/postgresql/postgresql-tutorial/postgresql-joins)\n\n#### 6. [Replace Employee ID With The Unique Identifier (1378)](https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/)\n\n```sql\nSELECT\n    e.name,\n    u.unique_id\nFROM\n    Employees e\nLEFT JOIN\n    EmployeeUNI u\n        ON e.id = u.id;\n```\n\n#### 7. [Product Sales Analysis I (1068)](https://leetcode.com/problems/product-sales-analysis-i/)\n\n```sql\nSELECT\n    p.product_name,\n    s.year,\n    s.price\nFROM\n    Sales s\nNATURAL JOIN\n    Product p\n```\n\n#### 8. [Customer Who Visited but Did Not Make Any Transactions (1581)](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions)\n\n```sql\nSELECT\n    v.customer_id,\n    COUNT(*)\n        AS count_no_trans\nFROM\n    Visits v\nLEFT JOIN\n    Transactions t\n        ON t.visit_id = v.visit_id\nWHERE\n    t.transaction_id\n        IS NULL\nGROUP BY\n    v.customer_id;\n```\n\n#### 9. [Rising Temperature (197)](https://leetcode.com/problems/rising-temperature/)\n\n```sql\nSELECT\n    w2.id\nFROM\n    Weather w1\nINNER JOIN\n    Weather w2\n    ON w2.temperature \u003e w1.temperature\nWHERE\n    w2.recordDate::date - w1.recordDate::date = 1\n```\n\n#### 10. [Average Time of Process per Machine (1661)](https://leetcode.com/problems/average-time-of-process-per-machine/)\n\n```sql\nSELECT\n    a2.machine_id,\n    ROUND(AVG(a2.timestamp - a1.timestamp)::numeric, 3)  -- or, decimal\n        AS processing_time\nFROM\n    Activity a1\nINNER JOIN\n    Activity a2\n    ON a2.machine_id = a1.machine_id\nWHERE\n    a2.activity_type = 'end'\n    AND a1.activity_type = 'start'\nGROUP BY\n    a2.machine_id\n```\n\n\u003e The `::` operator is used to cast a value to a specific data type.\n\u003e\n\u003e - [PostgreSQL numeric data types](https://www.postgresql.org/docs/current/datatype-numeric.html) docs\n\n#### 11. [Employee Bonus (577)](https://leetcode.com/problems/employee-bonus/)\n\n```sql\nSELECT\n    e.name,\n    b.bonus\nFROM\n    Employee e\nLEFT JOIN\n    Bonus b\n        ON b.empId = e.empId\nWHERE\n    b.bonus \u003c 1000\n    OR\n    b.bonus IS NULL;\n```\n\n#### 12. [Students and Examinations (1280)](https://leetcode.com/problems/students-and-examinations/)\n\n```sql\nSELECT\n    st.student_id,\n    st.student_name,\n    su.subject_name,\n    COUNT(e.subject_name)\n        AS attended_exams\nFROM\n    Students st\nCROSS JOIN\n    Subjects su\nLEFT JOIN\n    Examinations e\n    ON\n        e.student_id = st.student_id\n        AND\n        e.subject_name = su.subject_name\nGROUP BY\n    st.student_id,\n    st.student_name,\n    su.subject_name\nORDER BY\n    st.student_id,\n    su.subject_name;\n```\n\n#### 13. [Managers with at Least 5 Direct Reports (570)](https://leetcode.com/problems/managers-with-at-least-5-direct-reports)\n\n```sql\n-- using subquery\nSELECT\n    name\nFROM\n    Employee\nWHERE\n    id IN (\n        SELECT\n            managerId\n        FROM\n            Employee\n        WHERE\n            managerId\n                IS NOT NULL\n        GROUP BY\n            managerId\n        HAVING\n            COUNT(*) \u003e= 5\n    )\n```\n\n```sql\n-- using join\nSELECT\n    e1.name\nFROM\n    Employee e1\nJOIN\n    Employee e2\n    ON\n        e2.managerId = e1.id\nWHERE\n    e2.managerId\n        IS NOT NULL\nGROUP BY\n    e1.name, e1.id  -- allow multiple name\nHAVING\n    COUNT(*) \u003e= 5;\n```\n\n#### 14. [Confirmation Rate (1934)](https://leetcode.com/problems/confirmation-rate/)\n\n```sql\nSELECT\n    s.user_id,\n    ROUND(\n        COUNT(*) FILTER (WHERE c.action='confirmed')::decimal / COUNT(*),\n        2\n    ) AS confirmation_rate\nFROM\n    Signups s\nLEFT JOIN\n    Confirmations c\n    ON\n        c.user_id = s.user_id\nGROUP BY\n    s.user_id\n```\n\n## Basic Aggregate Functions\n\n#### 15. [Not Boring Movies (620)](https://leetcode.com/problems/not-boring-movies)\n\n```sql\nSELECT\n    *\nFROM\n    Cinema\nWHERE\n    id % 2 = 1\n    AND\n    description \u003c\u003e 'boring'\nORDER BY\n    rating DESC;\n```\n\n#### 16. [Average Selling Price (1251)](https://leetcode.com/problems/average-selling-price)\n\n```sql\nSELECT\n    p.product_id,\n    COALESCE(\n        ROUND(\n            SUM(u.units * p.price)::decimal / SUM(u.units), 2\n        ), 0\n    ) AS average_price\nFROM\n    Prices p\nLEFT JOIN\n    UnitsSold u\n    ON u.product_id = p.product_id\n    AND\n    u.purchase_date BETWEEN p.start_date AND p.end_date\nGROUP BY\n    p.product_id\n```\n\n#### 17. [Project Employees I (1075)](https://leetcode.com/problems/project-employees-i)\n\n```sql\nSELECT\n    p.project_id,\n    ROUND(\n        AVG(e.experience_years), 2\n    ) AS average_years\nFROM\n    Project p\nNATURAL JOIN\n    Employee e\nGROUP BY\n    p.project_id\n```\n\n#### 18. [Percentage of Users Attended a Contest (1633)](https://leetcode.com/problems/percentage-of-users-attended-a-contest)\n\n```sql\nSELECT\n    r.contest_id,\n    ROUND(\n        COUNT(r.user_id)::decimal / (SELECT COUNT(*) FROM Users) * 100.0,\n        2\n    ) AS percentage\nFROM\n    Users u\nNATURAL JOIN\n    Register r\nGROUP BY\n    r.contest_id\nORDER BY\n    percentage DESC,\n    contest_id\n```\n\n#### 19. [Queries Quality and Percentage (1211)](https://leetcode.com/problems/queries-quality-and-percentage/description)\n\n```sql\nSELECT\n    query_name,\n    ROUND(\n        AVG(rating::decimal / position), 2\n    ) AS quality,\n    ROUND(\n        (COUNT(*) FILTER(WHERE rating \u003c 3))::decimal * 100 / COUNT(*), 2\n    ) AS poor_query_percentage\nFROM\n    Queries\nGROUP BY\n    query_name\n```\n\n#### 20. [Monthly Transactions I (1193)](https://leetcode.com/problems/monthly-transactions-i/description) :star2:\n\n```sql\nSELECT\n    to_char(trans_date, 'YYYY-MM') AS month,\n    country,\n    COUNT(*) AS trans_count,\n    COUNT(*) FILTER(WHERE state='approved') AS approved_count,\n    COALESCE(\n        SUM(amount), 0\n    ) AS trans_total_amount,\n    COALESCE(\n        SUM(amount) FILTER(WHERE state='approved'), 0\n    ) AS approved_total_amount\nFROM\n    Transactions\nGROUP BY\n    month,\n    country\n```\n\n\u003e #### 1. `to_char` Function\n\u003e\n\u003e - to format dates, timestamps, and intervals into human-readable strings. It's incredibly versatile, allowing you to customize the output precisely.\n\u003e\n\u003e ```sql\n\u003e to_char(expression, format_string)\n\u003e ```\n\u003e\n\u003e - `expression`: The date, timestamp, or interval value you want to format.\n\u003e - `format_string`: A template string specifying how the output should look. This is where you control the format.\n\u003e\n\u003e **Format String Elements (Common Examples):**\n\u003e\n\u003e - `YYYY`: Four-digit year (e.g., 2023)\n\u003e - `YY`: Two-digit year (e.g., 23)\n\u003e - `MM`: Two-digit month (e.g., 01 for January, 12 for December)\n\u003e - `Month`: Full month name (e.g., January)\n\u003e - `Mon`: Abbreviated month name (e.g., Jan)\n\u003e - `DD`: Two-digit day of the month (e.g., 01, 31)\n\u003e - `Day`: Full day of the week (e.g., Monday)\n\u003e - `Dy`: Abbreviated day of the week (e.g., Mon)\n\u003e - `HH`: Hour (24-hour clock)\n\u003e - `HH12`: Hour (12-hour clock)\n\u003e - `MI`: Minutes\n\u003e - `SS`: Seconds\n\u003e - `MS`: Milliseconds\n\u003e - `US`: Microseconds\n\u003e - `TZ`: Time zone abbreviation (e.g., IST, PST)\n\u003e - `CC`: Century\n\u003e\n\u003e **Examples of `to_char`:**\n\u003e\n\u003e ```sql\n\u003e SELECT to_char(now(), 'YYYY-MM-DD HH24:MI:SS');  -- Current date and time\n\u003e SELECT to_char(date '2024-03-15', 'Month DD, YYYY'); -- March 15, 2024\n\u003e SELECT to_char(timestamp '2023-10-27 10:30:00', 'Day, Mon DD YYYY HH12:MI AM'); -- Friday, Oct 27 2023 10:30 AM\n\u003e SELECT to_char(interval '2 years 3 months', 'YY years MM months'); -- 02 years 03 months\n\u003e ```\n\u003e\n\u003e #### 2. `date_part` Function\n\u003e\n\u003e The `date_part` function extracts a specific component (like year, month, day, hour, etc.) from a date, timestamp, or interval.\n\u003e\n\u003e ```sql\n\u003e date_part('field', source)\n\u003e ```\n\u003e\n\u003e - `field`: The part of the date/time you want to extract (e.g., 'year', 'month', 'day', 'hour', 'minute', 'second', 'dow' (day of week), 'doy' (day of year), 'week', 'quarter').\n\u003e - `source`: The date, timestamp, or interval value.\n\u003e\n\u003e **Examples of `date_part`:**\n\u003e\n\u003e ```sql\n\u003e SELECT date_part('year', date '2024-03-15');  -- 2024\n\u003e SELECT date_part('month', timestamp '2023-10-27 10:30:00'); -- 10\n\u003e SELECT date_part('day', date '2024-03-15');   -- 15\n\u003e SELECT date_part('dow', date '2024-03-15');  -- 5 (Friday, where Sunday = 0)\n\u003e SELECT date_part('hour', timestamp '2023-10-27 10:30:00'); -- 10\n\u003e SELECT date_part('week', date '2024-03-15'); -- 11 (week number of the year)\n\u003e SELECT date_part('quarter', date '2024-05-15'); -- 2\n\u003e ```\n\u003e\n\u003e **Key Differences and When to Use Which:**\n\u003e\n\u003e - **`to_char`:** Use this when you need to _format_ a date/time/interval into a specific string representation. You have fine-grained control over the output format. Think of it as converting a date/time into a _textual representation_.\n\u003e - **`date_part`:** Use this when you need to _extract_ a specific component (a number) from a date/time/interval. It gives you a numeric value representing that part. Think of it as getting a _numerical value_ representing a date/time part.\n\n#### 21. [Immediate Food Delivery II (1174)](https://leetcode.com/problems/immediate-food-delivery-ii/description) :star2:\n\n```sql\nWITH first_order_cte AS (\n    SELECT\n        customer_id,\n        MIN(order_date) AS first_order\n    FROM\n        Delivery\n    GROUP BY\n        customer_id\n),\n\nimmediate_order_cte AS (\n    SELECT\n        d.customer_id,\n        MIN(d.customer_pref_delivery_date) AS immediate_delivery\n    FROM\n        Delivery d\n    JOIN\n        first_order_cte fo\n        ON fo.customer_id = d.customer_id\n    GROUP BY\n        d.customer_id\n)\n\nSELECT\n    ROUND(\n        COUNT(*) FILTER(WHERE f.first_order = i.immediate_delivery)::decimal * 100\n        /\n        COUNT(f.customer_id), 2\n    ) AS immediate_percentage\nFROM\n    first_order_cte f\nJOIN\n    immediate_order_cte i\n    ON\n        i.customer_id = f.customer_id\n```\n\n```sql\nSELECT\n    ROUND(\n        AVG((order_date = customer_pref_delivery_date)::int) * 100,\n        2\n    ) AS immediate_percentage\nFROM\n    Delivery\nWHERE (customer_id, order_date) IN (\n    SELECT\n        customer_id,\n        MIN(order_date)\n    FROM\n        Delivery\n    GROUP BY\n        customer_id\n)\n```\n\n\u003e **Common Table Expressions (CTEs):**\n\u003e\n\u003e - CTEs are temporary result sets that you can reference within a SELECT, INSERT, UPDATE, or DELETE statement.\n\u003e - They help break down complex queries into smaller, more manageable parts.\n\u003e\n\u003e **Syntax:**\n\u003e\n\u003e ```sql\n\u003e WITH cte_name (column1, column2, ...) AS (\n\u003e     subquery\n\u003e )\n\u003e SELECT columns\n\u003e FROM cte_name\n\u003e WHERE condition;\n\u003e ```\n\u003e\n\u003e - `cte_name`: The name of the Common Table Expression.\n\u003e - `(column1, column2, ...)`: An optional list of column names for the CTE.\n\u003e - `subquery`: The subquery that defines the CTE.\n\u003e - `SELECT columns`: The main query that references the CTE.\n\u003e - `WHERE condition`: An optional condition to filter the results.\n\n#### 22. [Game Play Analysis IV (550)](https://leetcode.com/problems/game-play-analysis-iv)\n\n```sql\n-- Step 1: Find the first login date for each player\n\nWITH FirstLogin AS (\n    SELECT\n        player_id,\n        MIN(event_date)\n            AS first_login\n    FROM\n        Activity\n    GROUP BY\n        player_id\n),\n\n-- Step 2: Check if the player logged in the day after their first login\n\nNextDayLogin AS (\n    SELECT\n        a.player_id\n    FROM\n        FirstLogin f\n    JOIN\n        Activity a\n        ON\n            a.player_id = f.player_id\n        AND\n            a.event_date = f.first_login + INTERVAL '1 DAY'\n)\n\n-- Step 3: Calculate the fraction of players who logged in the next day\n\nSELECT\n    ROUND(\n        COUNT(*) FILTER(WHERE f.player_id = n.player_id)::decimal / COUNT(*),\n        2\n    ) AS fraction\nFROM\n    FirstLogin f\nLEFT JOIN\n    NextDayLogin n\n    ON\n        f.player_id = n.player_id\n```\n\n\u003e In PostgreSQL, the `INTERVAL` data type is used to store and manipulate periods of time. It's an extremely useful feature when you need to perform date and time calculations.\n\u003e\n\u003e Here's what you should know about PostgreSQL intervals:\n\u003e\n\u003e #### Basic Syntax\n\u003e\n\u003e ```sql\n\u003e INTERVAL '1 day'\n\u003e INTERVAL '2 hours 30 minutes'\n\u003e INTERVAL '1 year 2 months 3 days'\n\u003e ```\n\u003e\n\u003e #### Common Interval Units\n\u003e\n\u003e PostgreSQL supports these interval units:\n\u003e\n\u003e - `year`, `month`, `week`, `day`\n\u003e - `hour`, `minute`, `second`, `millisecond`, `microsecond`\n\u003e - Abbreviations like `yr`, `mon`, `h`, `min`, `sec` are also recognized\n\u003e\n\u003e #### Date/Time Arithmetic\n\u003e\n\u003e You can use intervals for date calculations:\n\u003e\n\u003e ```sql\n\u003e -- Add 3 days to a date\n\u003e SELECT date '2025-03-03' + INTERVAL '3 days';\n\u003e\n\u003e -- Subtract 1 month from a timestamp\n\u003e SELECT now() - INTERVAL '1 month';\n\u003e\n\u003e -- Calculate time difference\n\u003e SELECT age(timestamp '2025-03-03', timestamp '2025-01-01');\n\u003e ```\n\u003e\n\u003e #### Extracting Parts\n\u003e\n\u003e You can extract specific parts from an interval:\n\u003e\n\u003e ```sql\n\u003e SELECT EXTRACT(day FROM INTERVAL '1 year 2 months 3 days 4 hours');\n\u003e -- Returns: 3\n\u003e ```\n\u003e\n\u003e #### Interval Constants\n\u003e\n\u003e PostgreSQL allows shorthand notation:\n\u003e\n\u003e ```sql\n\u003e '1 day'::interval\n\u003e '2 hours'::interval\n\u003e ```\n\u003e\n\u003e #### Practical Example\n\u003e\n\u003e ```sql\n\u003e -- Find all records created in the last 7 days\n\u003e SELECT * FROM records\n\u003e WHERE created_at \u003e now() - INTERVAL '7 days';\n\u003e ```\n\u003e\n\u003e #### Functions\n\u003e\n\u003e PostgreSQL offers functions for interval manipulation:\n\u003e\n\u003e ```sql\n\u003e -- Justify hours (convert hours to days when possible)\n\u003e SELECT justify_hours(INTERVAL '30 hours'); -- Returns '1 day 6 hours'\n\u003e\n\u003e -- Justify days (convert days to months when possible)\n\u003e SELECT justify_days(INTERVAL '40 days'); -- Returns '1 month 10 days'\n\u003e ```\n\u003e\n\u003e Intervals are particularly valuable in reporting, data analysis, and applications that need to track time differences or schedule recurring events.\n\n\n## Sorting and Grouping\n\n#### 23. [Number of Unique Subjects Taught by Each Teacher (2356)](https://leetcode.com/problems/number-of-unique-subjects-taught-by-each-teacher)\n\n```sql\nSELECT\n    teacher_id,\n    COUNT(DISTINCT subject_id)\n        AS cnt\nFROM\n    Teacher\nGROUP BY\n    teacher_id\n```\n\n#### 24. [User Activity for the Past 30 Days I (1141)](https://leetcode.com/problems/user-activity-for-the-past-30-days-i)\n\n```sql\nSELECT\n    activity_date\n        AS day,\n    COUNT(DISTINCT user_id)\n        AS active_users\nFROM\n    Activity\nWHERE\n    activity_date\n        BETWEEN\n            '2019-07-27'::date - INTERVAL '29 days'\n            AND\n            '2019-07-27'::date\nGROUP BY\n    activity_date\n```\n\n## Contributing\n\nIf you'd like to contribute, feel free to fork this repository and submit a pull request with your solutions or improvements. Make sure to follow the same format for consistency.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falokshandilya%2Fsql50-leetcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falokshandilya%2Fsql50-leetcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falokshandilya%2Fsql50-leetcode/lists"}