{ "data": { "question": { "questionId": "2057", "questionFrontendId": "1907", "boundTopicId": null, "title": "Count Salary Categories", "titleSlug": "count-salary-categories", "content": "
Table: Accounts
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| account_id | int |\n| income | int |\n+-------------+------+\naccount_id is the primary key (column with unique values) for this table.\nEach row contains information about the monthly income for one bank account.\n\n\n
\n\n
Write a solution to calculate the number of bank accounts for each salary category. The salary categories are:
\n\n"Low Salary"
: All the salaries strictly less than $20000
."Average Salary"
: All the salaries in the inclusive range [$20000, $50000]
."High Salary"
: All the salaries strictly greater than $50000
.The result table must contain all three categories. If there are no accounts in a category, return 0
.
Return the result table in any order.
\n\nThe result format is in the following example.
\n\n\n
Example 1:
\n\n\nInput: \nAccounts table:\n+------------+--------+\n| account_id | income |\n+------------+--------+\n| 3 | 108939 |\n| 2 | 12747 |\n| 8 | 87709 |\n| 6 | 91796 |\n+------------+--------+\nOutput: \n+----------------+----------------+\n| category | accounts_count |\n+----------------+----------------+\n| Low Salary | 1 |\n| Average Salary | 0 |\n| High Salary | 3 |\n+----------------+----------------+\nExplanation: \nLow Salary: Account 2.\nAverage Salary: No accounts.\nHigh Salary: Accounts 3, 6, and 8.\n\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Medium", "likes": 312, "dislikes": 61, "isLiked": null, "similarQuestions": "[{\"title\": \"Create a Session Bar Chart\", \"titleSlug\": \"create-a-session-bar-chart\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]", "exampleTestcases": "{\"headers\":{\"Accounts\":[\"account_id\",\"income\"]},\"rows\":{\"Accounts\":[[3,108939],[2,12747],[8,87709],[6,91796]]}}", "categoryTitle": "Database", "contributors": [], "topicTags": [ { "name": "Database", "slug": "database", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below\n", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Pandas", "langSlug": "pythondata", "code": "import pandas as pd\n\ndef count_salary_categories(accounts: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below\n", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"47.9K\", \"totalSubmission\": \"82.8K\", \"totalAcceptedRaw\": 47868, \"totalSubmissionRaw\": 82796, \"acRate\": \"57.8%\"}", "hints": [], "solution": { "id": "2021", "canSeeDetail": false, "paidOnly": true, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "{\"headers\":{\"Accounts\":[\"account_id\",\"income\"]},\"rows\":{\"Accounts\":[[3,108939],[2,12747],[8,87709],[6,91796]]}}", "metaData": "{\"mysql\": [\"Create table If Not Exists Accounts (account_id int, income int)\"], \"mssql\": [\"Create table Accounts (account_id int, income int)\"], \"oraclesql\": [\"Create table Accounts (account_id int, income int)\"], \"database\": true, \"name\": \"count_salary_categories\", \"pythondata\": [\"Accounts = pd.DataFrame([], columns=['account_id', 'income']).astype({'account_id':'Int64', 'income':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Accounts (account_id int, income int)\"], \"database_schema\": {\"Accounts\": {\"account_id\": \"INT\", \"income\": \"INT\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Accounts (account_id int, income int)", "Truncate table Accounts", "insert into Accounts (account_id, income) values ('3', '108939')", "insert into Accounts (account_id, income) values ('2', '12747')", "insert into Accounts (account_id, income) values ('8', '87709')", "insert into Accounts (account_id, income) values ('6', '91796')" ], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"mysql\": [\"MySQL\", \"
MySQL 8.0
.
mssql server 2019
.
Oracle Sql 11.2
.
Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0
\"], \"postgresql\": [\"PostgreSQL\", \"PostgreSQL 16
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }