Skip to content

Commit 31c2a14

Browse files
committed
task: #1795
1 parent 8afc813 commit 31c2a14

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Useful for preparing for technical interviews and improving your SQL skills.
144144
- [1731. The Number of Employees Which Report to Each Employee](./leetcode/easy/1731.%20The%20Number%20of%20Employees%20Which%20Report%20to%20Each%20Employee.sql)
145145
- [1741. Find Total Time Spent by Each Employee](./leetcode/easy/1741.%20Find%20Total%20Time%20Spent%20by%20Each%20Employee.sql)
146146
- [1789. Primary Department for Each Employee](./leetcode/easy/1789.%20Primary%20Department%20for%20Each%20Employee.sql)
147+
- [1795. Rearrange Products Table](./leetcode/easy/1795.%20Rearrange%20Products%20Table.sql)
147148
- [1965. Employees With Missing Information](./leetcode/easy/1965.%20Employees%20With%20Missing%20Information.sql)
148149
- [1978. Employees Whose Manager Left the Company](./leetcode/easy/1978.%20Employees%20Whose%20Manager%20Left%20the%20Company.sql)
149150
- [2356. Number of Unique Subjects Taught by Each Teacher](./leetcode/easy/2356.%20Number%20of%20Unique%20Subjects%20Taught%20by%20Each%20Teacher.sql)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Question 1795. Rearrange Products Table
3+
Link: https://leetcode.com/problems/rearrange-products-table/description/?envType=problem-list-v2&envId=database
4+
5+
Table: Products
6+
7+
+-------------+---------+
8+
| Column Name | Type |
9+
+-------------+---------+
10+
| product_id | int |
11+
| store1 | int |
12+
| store2 | int |
13+
| store3 | int |
14+
+-------------+---------+
15+
product_id is the primary key (column with unique values) for this table.
16+
Each row in this table indicates the product's price in 3 different stores: store1, store2, and store3.
17+
If the product is not available in a store, the price will be null in that store's column.
18+
19+
20+
Write a solution to rearrange the Products table so that each row has (product_id, store, price). If a product is not available in a store, do not include a row with that product_id and store combination in the result table.
21+
22+
Return the result table in any order.
23+
*/
24+
25+
SELECT
26+
product_id,
27+
'store1' AS store,
28+
store1 AS price
29+
FROM Products
30+
WHERE store1 IS NOT NULL
31+
32+
UNION ALL
33+
34+
SELECT
35+
product_id,
36+
'store2' AS store,
37+
store2 AS price
38+
FROM Products
39+
WHERE store2 IS NOT NULL
40+
41+
UNION ALL
42+
43+
SELECT
44+
product_id,
45+
'store3' AS store,
46+
store3 AS price
47+
FROM Products
48+
WHERE store3 IS NOT NULL

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy