我有下表:
bar_id, bar_name, subscription_id_fk, sub_name
例如:
1, Hard Rock, 2, Gold
2, TGIF, 1, Free
现在我需要和SQL来提取这个表,但是在sub_name = Gold的情况下,我需要将subscription_id_fk加倍。
你能帮忙吗? ?编辑: 我需要仅在SQL statment
的结果中更改此值答案 0 :(得分:2)
SELECT IF(sub_name = 'Gold', subscription_id_fk * 2, subscription_id_fk) as fk
FROM my_table
答案 1 :(得分:0)
也许我不明白这个问题,但这看起来像是对我的简单更新:
UPDATE table
SET subscription_id_fk = (subscription_id_fk * 2)
WHERE sub_name = "Gold"
答案 2 :(得分:0)
您是否正在寻找像
这样简单的事情SELECT (subscription_id_fk * 2) as double_sif
FROM table
WHERE sub_name = 'Gold'
正如你接受了这个答案的一些评论
答案 3 :(得分:0)
This可能对您有帮助。
所以,根据您尝试的链接,
select subscription_id_fk * 2 from table where sub_name = 'Gold'
我没有尝试过它。我只是在互联网上找到它。所以,试试吧。
答案 4 :(得分:0)
好的,如果您需要所有行,但只需要带有双键的“Gold”-one,您可以使用
SELECT
GREATEST(t.subscription_id_fk, IFNULL(t2.subscription_id_fk,0)) AS subscription_id_fk,
bar_id,
bar_name,
sub_name
FROM table AS t
LEFT JOIN (
SELECT (subscription_id_fk * 2) AS subscription_id_fk,
id
FROM table t2
WHERE sub_name ="Gold") AS t2
ON (t.id = t2.id)