You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-1Lines changed: 44 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1726,7 +1726,7 @@ GROUP BY
1726
1726
1727
1727
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**
1728
1728
1729
-
## 50. Customer Who Visited but did not Make any Purchases
1729
+
## 50. Customers Who Visited but did not Make any Purchases
1730
1730
1731
1731
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:
1732
1732
@@ -1787,3 +1787,46 @@ GROUP BY
1787
1787
---
1788
1788
1789
1789
**[⬆ 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=2021AND revenue >0;
1826
+
```
1827
+
1828
+
</details>
1829
+
1830
+
---
1831
+
1832
+
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**
0 commit comments