Home > database >  How the SQL statement to update twice the price of a table
How the SQL statement to update twice the price of a table

Time:05-08

all the unit price discount of 8.8 is greater than or equal to 3000 products, 9 discount price is less than 3000 products, update relevant information,
The update
The set statement how to implement,

CodePudding user response:

The UPDATE table SET price=(CASE WHEN the unit price & lt; 3000 THEN the unit price * 0.9 ELSE unit price * 0.88 END)

CodePudding user response:

reference 1/f, kun jins kao kun jins kao response:
UPDATE table SET price=(CASE WHEN the unit price & lt; 3000 THEN the unit price * 0.9 ELSE unit price * 0.88 END)
where clause is necessary, isn't it, please put the price of judgment after the where clause

CodePudding user response:

refer to the second floor weixin_53839792 response:
Quote: refer to 1st floor kun jins kao kun jins kao response:
UPDATE table SET price=(CASE WHEN the unit price & lt; 3000 THEN the unit price * 0.9 ELSE unit price * 0.88 END)
where clause is necessary, isn't it, please put the determine the price after the where clause ok

The UPDATE table SET price=price * 0.9 WHERE the unit price & lt; 3000

The UPDATE table SET price=price * 0.88 WHERE the unit price & gt;=3000

Use the where

CodePudding user response:

Here in case the when need not the where, with the where seems to be more troublesome, in order to write two
The UPDATE table SET price=price * 0.9 WHERE the unit price & lt; 3000
The UPDATE table SET price=price * 0.88 WHERE the unit price & gt;=3000

CodePudding user response:

update product
The set price=price * 0.88
Where price>=3000
The set price=price * 0.9
Where price<3000
Go
that right is not very specific writing

CodePudding user response:

Isn't it takes two to make a update
  • Related