比如表A
id name regdate
用sql求出一共有多少name相同的人,
再写一个语句,把name相同的人存储到B表 ,字段和A一样;
最后一个语句:A中name相同的记录,只留下注册时间最早的,其它删除
关于计算列中同值记录条数的sql
答案:2 悬赏:70 手机版
解决时间 2021-01-24 21:46
- 提问者网友:蔚蓝的太阳
- 2021-01-24 12:41
最佳答案
- 五星知识达人网友:一叶十三刺
- 2021-01-24 13:30
一楼的答案估计够呛,
一问:
select count(name) from A group by name having count(name)>1
二问:
select * into B from A group by name having count(name)>1
三问:
select id,name,min(regdate) into temp_table from A group by name,id,redate having count(name)>1
drop table A
select * into A from temp_table
drop table temp_table
一问:
select count(name) from A group by name having count(name)>1
二问:
select * into B from A group by name having count(name)>1
三问:
select id,name,min(regdate) into temp_table from A group by name,id,redate having count(name)>1
drop table A
select * into A from temp_table
drop table temp_table
全部回答
- 1楼网友:底特律间谍
- 2021-01-24 14:57
用sql求出一共有多少name相同的人
select count(name) from A having count(name)>1
把name相同的人存储到B表 ,字段和A一样
insert into b select name from A having count(name)>1
A中name相同的记录,只留下注册时间最早的,其它删除
select * from A where ID in ((select v.id from (select max(getdate()-regdate),ID from A having count(name)>1)v)t
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯