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

标签 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"
)
;

最佳答案

这是你想要的吗?

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;

关于mysql - 在子查询中更改值时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37779794/

相关文章:

mysql - INSERT INTO SELECT 不起作用

php - 根据下拉选择显示特定的 MySQL 行

Sql select 在表上插入时速度很慢

mysql - 连接的子查询(存在/存在)

mysql - 嵌套查询——有没有更聪明的方法

mysql - 综合指数与个人指数

python - 在 SQLAlchemy 中获取按相同字段值分组的结果

PHP 在 SQL 表之间移动信息

PHPExcel 标题行覆盖第一个条目

mysql - 如何从两个不同表的连接结果中删除重复数据?