sql中,如果有两条一样的数据,根据某个字段的不同,去最小的一条数据插入表中怎么写
?
insert into tablename() value(select name from tablename where arg1<arg2);
insert(字段) into table (select 字段 from table where 条件)
使用min函数试试看看
先用代码,找到最少的数据,然后再这SQL语句插入数据。
如果是有的是一条有的是两条,你先把数据分以下组再添加 比如----select * from tablename group by sid 这是根据sid分组,
完整的可以是这样 insert into studenttwo( id,name,class ) select id,name,class from student group by name
也可以加个条件 insert into studenttwo( id,name,class ) select id,name,class from student where name='小明' group by name