1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/每天的领导和合伙人 [daily-leads-and-partners].html
2022-03-29 12:43:11 +08:00

57 lines
2.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>表:<code>DailySales</code></p>
<pre>
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| date_id | date |
| make_name | varchar |
| lead_id | int |
| partner_id | int |
+-------------+---------+
该表没有主键。
该表包含日期、产品的名称,以及售给的领导和合伙人的编号。
名称只包含小写英文字母。</pre>
<p>&nbsp;</p>
<p>写一条 SQL 语句,使得对于每一个&nbsp;<code>date_id</code>&nbsp;&nbsp;<code>make_name</code>,返回<strong>不同</strong>&nbsp;<code>lead_id</code>&nbsp;以及<strong>不同</strong>&nbsp;<code>partner_id</code>&nbsp;的数量。</p>
<p><strong>任意顺序</strong> 返回结果表。</p>
<p>查询结果格式如下示例所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>
DailySales 表:
+-----------+-----------+---------+------------+
| date_id | make_name | lead_id | partner_id |
+-----------+-----------+---------+------------+
| 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 |
+-----------+-----------+---------+------------+
<strong>输出:</strong>
+-----------+-----------+--------------+-----------------+
| date_id | make_name | unique_leads | unique_partners |
+-----------+-----------+--------------+-----------------+
| 2020-12-8 | toyota | 2 | 3 |
| 2020-12-7 | toyota | 1 | 2 |
| 2020-12-8 | honda | 2 | 2 |
| 2020-12-7 | honda | 3 | 2 |
+-----------+-----------+--------------+-----------------+
<strong>解释:</strong>
在 2020-12-8丰田toyota有领导者 = [0, 1] 和合伙人 = [0, 1, 2] 同时本田honda有领导者 = [1, 2] 和合伙人 = [1, 2]。
在 2020-12-7丰田toyota有领导者 = [0] 和合伙人 = [1, 2] 同时本田honda有领导者 = [0, 1, 2] 和合伙人 = [1, 2]。</pre>