读书人

怎么查询字段F2的重复值并在字段F15

发布时间: 2012-09-27 11:11:17 作者: rapoo

如何查询字段F2的重复值,并在字段F15中进行标记?
请教一个Update语句,功能如下:
Access中的一张表,检查表中F2字段是否有重复的记录,如果有重复的记录,就在该行字段F15中标记出“重复”。

例如:
tb1:
F1 F2 …… F15
1 Yun
2 CCL
3 CCL
4 Yun
5 WQE

运行结果后:
tb1:
F1 F2 …… F15
1 Yun
2 CCL
3 CCL……重复
4 Yun……重复
5 WQE

[解决办法]

SQL code
--tryupdate a  set F15=15 from tb as awhere exists(select 2 from tb where f2=a.f2 and f1<a.f1)
[解决办法]
SQL code
select F1,F2,case when exists(select 1 from tb b where a.F1=b.F1 then ‘重复' else '' end as F15 from tb a
[解决办法]
update tb1 set f15= cash when exists(select 1 from tb1 where a.f1=b.f1 then '重复'
else '' end
[解决办法]
SQL code
select F1,       F2,       case when        exists       (select 1 from tab b where a.F1=b.F1)       then ‘重复'       else '' end as F15 from tab a 

读书人网 >SQL Server

热点推荐