2014-10-18 47 views
0

我遇到問題,將我的惠普產品價格提高了10%。將產品價格提高10%

這裏是我試過 - >>

UPDATE products SET price = price*1.1; 
from products 
where prod_name like 'HP%' 

這裏是產品表的圖片:

enter image description here

+3

那究竟是什麼問題呢?你有錯誤嗎? – Mureinik 2014-10-18 22:07:39

+0

它是MySQL,對吧? – TarasB 2014-10-19 06:42:51

回答

0

這是您的查詢:

UPDATE products SET price = price*1.1; 
from products 
where prod_name like 'HP%' 

它與第二行中的分號的一個問題。此外,它不是標準的SQL(儘管這可以在一些數據庫中使用)。表達這種標準方式是:

update products 
    set price = price * 1.1 
    where prod_name like 'HP%'; 

from條款是沒有必要在這種情況下。

2

這是一個UPDATE,不是SELECT,所以FROM子句不正確。另外,分號應該在最後一行的末尾。

UPDATE products SET price = price*1.1; <== Remove the semicolon 
from products <== remove this line 
where prod_name like 'HP%' <== add a semicolon at the end of this line 

試試這個:

UPDATE products SET price = price*1.1 
where prod_name like 'HP%'; 
+2

可以在1.1旁邊使用分號嗎? – 2014-10-18 22:29:06

+0

哦,我錯過了。不,分號應從第一行開始移除,並添加到第二行的末尾。我會相應地編輯我的帖子。 – 2014-10-19 18:43:15

0

正確的查詢會是這樣的:

update products set price = price * 1.1 
where prod_name like 'HP%' ; 

不知道爲什麼你們都強調東芝?你想要更新嗎?