-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0821ae7
commit 651d51c
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |