Tutorialspoint

MySQL query to decrease value by 10 for a specific value?


1 Answer
Ankith Reddy

Let us first create a table −

mysql> create table DemoTable
   (
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   Score int
   );
Query OK, 0 rows affected (0.89 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable(Score) values(67);
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable(Score) values(78);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable(Score) values(90);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable(Score) values(56);
Query OK, 1 row affected (0.13 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+----+-------+
| Id | Score |
+----+-------+
| 1  | 67    |
| 2  | 78    |
| 3  | 90    |
| 4  | 56    |
+----+-------+
4 rows in set (0.00 sec)

Following is the query to decrease value by 10 for a specific value −

mysql> update DemoTable set Score=Score-10 where Id=3;
Query OK, 1 row affected (0.38 sec)
Rows matched : 1 Changed : 1 Warnings : 0

Let us check the table records once again −

mysql> select *from DemoTable;

Output

+----+-------+
| Id | Score |
+----+-------+
| 1  | 67    |
| 2  | 78    |
| 3  | 80    |
| 4  | 56    |
+----+-------+
4 rows in set (0.00 sec)

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.