Skip to content

Commit

Permalink
Q1795 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Mar 24, 2023
1 parent 0821ae7 commit 651d51c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions SQL/Q1795.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--Table: Products

--+-------------+---------+
--| Column Name | Type |
--+-------------+---------+
--| product_id | int |
--| store1 | int |
--| store2 | int |
--| store3 | int |
--+-------------+---------+
--product_id is the primary key for this table.
--Each row in this table indicates the product's price in 3 different stores: store1, store2, and store3.
--If the product is not available in a store, the price will be null in that store's column.


--Write an SQL query 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.


/* Write your T-SQL query statement below */
select product_id, 'store1' as store, store1 as price from Products p
where store1 is not NULL
UNION
select product_id, 'store2' as store, store2 as price from Products p
where store2 is not NULL
UNION
select product_id, 'store3' as store, store3 as price from Products p
where store3 is not NULL

0 comments on commit 651d51c

Please sign in to comment.