在子查询中更改值时遇到问题

时间:2016-06-12 22:43:22

标签: mysql sql subquery mysql-workbench

我正在尝试使用items.unit_price,在子查询中将其值增加10%,然后将其显示在另一列中。

这是我的代码

select items.title, items.unit_price, items.unit_price as Price_increase
from artists
join items
on items.artist_id = artists.artist_id
order by price_increase in
(
    select distinct round(items.unit_price + (items.unit_price * 0.1), 2) as Price_increase
    from artists
    where artists.artist_name = "No Rest For The Weary"
)
;

1 个答案:

答案 0 :(得分:1)

这是你想要的吗?

select i.title, i.unit_price,
       (case when a.artist_name = 'No Rest For The Weary'
             then 1.1*i.unit_price else i.unit_price
        end) as Price_increase
from artists a join
     items i
     on i.artist_id = a.artist_id
order by price_increase;