设1表中有A、B两列,我想添加一组数据(c,d)进去(并没有C的值),其中c=A列最大值+1,
如何写sql语句?
Ps.我知道如果只添加C可以这么写:
insert into 1(A)
select max(A)+1
from 1;
但是我想同时将数据d添加进去
其实你已经知道方法了。
insert into 1(A,B) select max(A),d from test;
在这里d要是一个常量值或者是test表的字段;
insert into tableA(c) select sum(A) from xxx
SELECT A,B,c,d FROM 表1
,(select max(a)+1 c from 表1)
,(select max(b)+1 d from 表1)
我刚回复的最大值少了+1。你写了max(A)+1会报错?什么错?