此题一眼看去完全不会,经题解指点,发现可以讲常数值直接定位列的值,结合union可以非常巧妙额解决,于是我就画了个葫芦。
select
product_id, 'store1' as store, store1 as price
from
products
where
store1 != null
然后离谱的事就发生了,tm的就不对啊。然后我就研究了一会,发现原来sql是不能!=null的,一定要is not null才行。
# Write your MySQL query statement below
select
product_id, 'store1' as store, store1 as price
from
products
where
store1 is not null
union
select
product_id, 'store2' as store, store2 as price
from
products
where
store2 is not null
union
select
product_id, 'store3' as store, store3 as price
from
products
where
store3 is not null