这是我的表
ID PARE BIAN VALUE1 应当正确 1 001
2 应当正确 2 002
3 应当正确 3 003
4 应当正确 0 004
5 应当正确 5 001
6 应当正确 6 002
7 应当正确 7 001
3 应当正确 1 003
下面是我的sql语句:
select * from table2 a where (select count(*) from table2 where coden=a.coden)>1 and not exists
(select * from table2 where coden=a.coden and dx>a.dx)
结果为:
ID PARE BIAN VALUE
3 应当正确 3 003
6 应当正确 6 002
7 应当正确 7 001现在要加一个作用,就是将'应当正确'改为'正确',请问这个sql语句怎么写???
ID PARE BIAN VALUE1 应当正确 1 001
2 应当正确 2 002
3 应当正确 3 003
4 应当正确 0 004
5 应当正确 5 001
6 应当正确 6 002
7 应当正确 7 001
3 应当正确 1 003
下面是我的sql语句:
select * from table2 a where (select count(*) from table2 where coden=a.coden)>1 and not exists
(select * from table2 where coden=a.coden and dx>a.dx)
结果为:
ID PARE BIAN VALUE
3 应当正确 3 003
6 应当正确 6 002
7 应当正确 7 001现在要加一个作用,就是将'应当正确'改为'正确',请问这个sql语句怎么写???
(select * from table2 where coden=a.coden and dx>a.dx)
CASE PARE WHEN '应该正确' THEN '正确' else PARE
END as PARE
,BIAN,VALUE
from table2 a where (select count(*) from table2 where coden=a.coden)>1 and not exists
(select * from table2 where coden=a.coden and dx>a.dx)
CASE PARE WHEN '应该正确' THEN '正确' else PARE
END as PARE
,BIAN,VALUE
from table2 a where (select count(*) from table2 where coden=a.coden)>1 and not exists
(select * from table2 where coden=a.coden and dx>a.dx)
--过滤数据到临时表
select * into #临时表 from table2 a where (select count(*) from table2 where coden=a.coden)>1 and not exists
(select * from table2 where coden=a.coden and dx>a.dx)
--更新
update #临时表 set PARE='正确' where Pare='应当正确'
--查询
select * from #临时表