0

I'm going to implement this function!

+-----+-----+
|name | age |
+-----+-----+
|Dong | 19  |
|Dung | 25  |
+-----+-----+

I want to increase column "age" by one like this:

+-----+-----+
|name | age |
+-----+-----+
|Dong | 20  |
|Dung | 26  |
+-----+-----+

pls help me solutions!!

There were twos solution which I thought:
1) using UPDATE sqlCommand. update x set a = a + 1 where a = "age"

2) create new column = old column + 1 then replace old column by new one.

1 Answers1

3

2 possible answer.

  1. Do you want to increase the age permanently? If yes, just update the data.

    update tbl1 set age = age + 1;
    
  2. If you only want show the age + 1 when you view the data:

    select name, age + 1 as age from tbl
    
Iswanto San
  • 18,263
  • 13
  • 58
  • 79