Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b98207

Browse files
committed
Add a question
1 parent 7a3fce0 commit 0b98207

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,3 +1116,55 @@ WHERE LENGTH(content) > 15;
11161116
---
11171117

11181118
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**
1119+
1120+
## 37. Daily Leads and Partners
1121+
1122+
The `DailySales` table contains the date and the name of products sold and the IDs of the leads and partners they were sold to. Write a SQL query that for each `date_id` and `make_name`, returns the number of distinct `lead_id`'s and distinct `partner_id`'s. Here is an example:
1123+
1124+
```
1125+
DailySales table:
1126+
+-----------+-----------+---------+------------+
1127+
| date_id | make_name | lead_id | partner_id |
1128+
+-----------+-----------+---------+------------+
1129+
| 2020年12月8日 | toyota | 0 | 1 |
1130+
| 2020年12月8日 | toyota | 1 | 0 |
1131+
| 2020年12月8日 | toyota | 1 | 2 |
1132+
| 2020年12月7日 | toyota | 0 | 2 |
1133+
| 2020年12月7日 | toyota | 0 | 1 |
1134+
| 2020年12月8日 | honda | 1 | 2 |
1135+
| 2020年12月8日 | honda | 2 | 1 |
1136+
| 2020年12月7日 | honda | 0 | 1 |
1137+
| 2020年12月7日 | honda | 1 | 2 |
1138+
| 2020年12月7日 | honda | 2 | 1 |
1139+
+-----------+-----------+---------+------------+
1140+
```
1141+
1142+
```
1143+
Result table:
1144+
+-----------+-----------+--------------+-----------------+
1145+
| date_id | make_name | unique_leads | unique_partners |
1146+
+-----------+-----------+--------------+-----------------+
1147+
| 2020年12月8日 | toyota | 2 | 3 |
1148+
| 2020年12月7日 | toyota | 1 | 2 |
1149+
| 2020年12月8日 | honda | 2 | 2 |
1150+
| 2020年12月7日 | honda | 3 | 2 |
1151+
+-----------+-----------+--------------+-----------------+
1152+
```
1153+
1154+
<details><summary>Solution</summary>
1155+
1156+
```sql
1157+
SELECT
1158+
date_id,
1159+
make_name,
1160+
COUNT(DISTINCT(lead_id)) AS unique_leads,
1161+
COUNT(DISTINCT(partner_id)) AS unique_partners
1162+
FROM DailySales
1163+
GROUP BY date_id, make_name;
1164+
```
1165+
1166+
</details>
1167+
1168+
---
1169+
1170+
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /