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 37dba45

Browse files
committed
Add a question
1 parent 11c995a commit 37dba45

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

‎README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ GROUP BY
17261726

17271727
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**
17281728

1729-
## 50. Customer Who Visited but did not Make any Purchases
1729+
## 50. Customers Who Visited but did not Make any Purchases
17301730

17311731
At a members-only store, customers have to scan their membership cards before they can enter. Given a `Visits` table that contains information about the customers who visited the store, and a `Transactions` table that contains information about the purchases they made during their visits, write a SQL query to find the IDs of those customers who visited the store but made no purchases and the number of times they visited during which they did not purchase anything. Return the result table sorted in any order. Here is an example:
17321732

@@ -1787,3 +1787,46 @@ GROUP BY
17871787
---
17881788

17891789
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**
1790+
1791+
## 51. Customers with Positive Revenue
1792+
1793+
Write a SQL query to report the customers with positive revenue in the year 2021. Return the result table sorted in any order. Here is an example:
1794+
1795+
```
1796+
Customers
1797+
+-------------+------+---------+
1798+
| customer_id | year | revenue |
1799+
+-------------+------+---------+
1800+
| 1 | 2018 | 50 |
1801+
| 1 | 2021 | 30 |
1802+
| 1 | 2020 | 70 |
1803+
| 2 | 2021 | -50 |
1804+
| 3 | 2018 | 10 |
1805+
| 3 | 2016 | 50 |
1806+
| 4 | 2021 | 20 |
1807+
+-------------+------+---------+
1808+
```
1809+
1810+
```
1811+
Result table:
1812+
+-------------+
1813+
| customer_id |
1814+
+-------------+
1815+
| 1 |
1816+
| 4 |
1817+
+-------------+
1818+
```
1819+
1820+
<details><summary>Solution</summary>
1821+
1822+
```sql
1823+
SELECT customer_id
1824+
FROM Customers
1825+
WHERE year=2021 AND revenue > 0;
1826+
```
1827+
1828+
</details>
1829+
1830+
---
1831+
1832+
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

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