{ "data": { "question": { "questionId": "1837", "questionFrontendId": "1693", "boundTopicId": null, "title": "Daily Leads and Partners", "titleSlug": "daily-leads-and-partners", "content": "
Table: DailySales
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| date_id | date |\n| make_name | varchar |\n| lead_id | int |\n| partner_id | int |\n+-------------+---------+\nThis table does not have a primary key.\nThis table contains the date and the name of the product sold and the IDs of the lead and partner it was sold to.\nThe name consists of only lowercase English letters.\n\n\n
\n\n
Write an SQL query that will, for each date_id
and make_name
, return the number of distinct lead_id
's and distinct partner_id
's.
Return the result table in any order.
\n\nThe query result format is in the following example.
\n\n\n
Example 1:
\n\n\nInput: \nDailySales table:\n+-----------+-----------+---------+------------+\n| date_id | make_name | lead_id | partner_id |\n+-----------+-----------+---------+------------+\n| 2020-12-8 | toyota | 0 | 1 |\n| 2020-12-8 | toyota | 1 | 0 |\n| 2020-12-8 | toyota | 1 | 2 |\n| 2020-12-7 | toyota | 0 | 2 |\n| 2020-12-7 | toyota | 0 | 1 |\n| 2020-12-8 | honda | 1 | 2 |\n| 2020-12-8 | honda | 2 | 1 |\n| 2020-12-7 | honda | 0 | 1 |\n| 2020-12-7 | honda | 1 | 2 |\n| 2020-12-7 | honda | 2 | 1 |\n+-----------+-----------+---------+------------+\nOutput: \n+-----------+-----------+--------------+-----------------+\n| date_id | make_name | unique_leads | unique_partners |\n+-----------+-----------+--------------+-----------------+\n| 2020-12-8 | toyota | 2 | 3 |\n| 2020-12-7 | toyota | 1 | 2 |\n| 2020-12-8 | honda | 2 | 2 |\n| 2020-12-7 | honda | 3 | 2 |\n+-----------+-----------+--------------+-----------------+\nExplanation: \nFor 2020-12-8, toyota gets leads = [0, 1] and partners = [0, 1, 2] while honda gets leads = [1, 2] and partners = [1, 2].\nFor 2020-12-7, toyota gets leads = [0] and partners = [1, 2] while honda gets leads = [0, 1, 2] and partners = [1, 2].\n\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Easy", "likes": 97, "dislikes": 9, "isLiked": null, "similarQuestions": "[]", "exampleTestcases": "{\"headers\":{\"DailySales\":[\"date_id\",\"make_name\",\"lead_id\",\"partner_id\"]},\"rows\":{\"DailySales\":[[\"2020-12-8\",\"toyota\",0,1],[\"2020-12-8\",\"toyota\",1,0],[\"2020-12-8\",\"toyota\",1,2],[\"2020-12-7\",\"toyota\",0,2],[\"2020-12-7\",\"toyota\",0,1],[\"2020-12-8\",\"honda\",1,2],[\"2020-12-8\",\"honda\",2,1],[\"2020-12-7\",\"honda\",0,1],[\"2020-12-7\",\"honda\",1,2],[\"2020-12-7\",\"honda\",2,1]]}}", "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" } ], "stats": "{\"totalAccepted\": \"17.4K\", \"totalSubmission\": \"19.1K\", \"totalAcceptedRaw\": 17450, \"totalSubmissionRaw\": 19052, \"acRate\": \"91.6%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\":{\"DailySales\":[\"date_id\",\"make_name\",\"lead_id\",\"partner_id\"]},\"rows\":{\"DailySales\":[[\"2020-12-8\",\"toyota\",0,1],[\"2020-12-8\",\"toyota\",1,0],[\"2020-12-8\",\"toyota\",1,2],[\"2020-12-7\",\"toyota\",0,2],[\"2020-12-7\",\"toyota\",0,1],[\"2020-12-8\",\"honda\",1,2],[\"2020-12-8\",\"honda\",2,1],[\"2020-12-7\",\"honda\",0,1],[\"2020-12-7\",\"honda\",1,2],[\"2020-12-7\",\"honda\",2,1]]}}", "metaData": "{\n \"mysql\": [\n \"Create table If Not Exists DailySales(date_id date, make_name varchar(20), lead_id int, partner_id int)\"\n ],\n \"mssql\": [\n \"Create table DailySales(date_id date, make_name varchar(20), lead_id int, partner_id int)\"\n ],\n \"oraclesql\": [\n \"Create table DailySales(date_id date, make_name varchar(20), lead_id int, partner_id int)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists DailySales(date_id date, make_name varchar(20), lead_id int, partner_id int)", "Truncate table DailySales", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-8', 'toyota', '0', '1')", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-8', 'toyota', '1', '0')", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-8', 'toyota', '1', '2')", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-7', 'toyota', '0', '2')", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-7', 'toyota', '0', '1')", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-8', 'honda', '1', '2')", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-8', 'honda', '2', '1')", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-7', 'honda', '0', '1')", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-7', 'honda', '1', '2')", "insert into DailySales (date_id, make_name, lead_id, partner_id) values ('2020-12-7', 'honda', '2', '1')" ], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"mysql\": [\"MySQL\", \"
MySQL 8.0
.
mssql server 2019
.
Oracle Sql 11.2
.