现有表数据
1 22221 0
2 2222 0
3 2222 0
4 2222 0
5 3333 1
6 22221 0
7 2222 0
8 2222 0
9 2222 0
10 5555 1写一个查询语 查询出 这样效果1 22221 0
5 3333 1
6 22221 0
10 5555 1
那位大虾 会呀
CREATE TABLE [dbo].[Sg_KeepersResultLog](
[FId] [int] IDENTITY(1,1) NOT NULL,
[FContent] [text] NULL,
[ResultType] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]GO
表
解决方案 »
- sql查询不重复记录语句
- vs2005中有没有像Oracle那样的RollBack功能啊
- insert into TB1(id,name) values (select '1' as aa,select '2' as aa)
- 菜鸟提问
- 通过adsl上网的机器能用sp_addlinkedserver实现两个数据库的连接么?
- null使用随机的历史数据替换问题请教
- 启动SQL7.0中的Query Analyzer界面问题?
- 如何正确显示FLOAT类型字段的值
- 请各位大哥给我解决下这个问题! 急~~~!
- sql的性能优化……
- 使用sql语句如何知道一张表的表结构sql 语句该如何写
- sql2005 打不开表
where not exists
(select 1 from Sg_KeepersResultLog where Sg_KeepersResultLog=a.Sg_KeepersResultLog
and FId<a.FId)
列名 'Sg_KeepersResultLog' 无效。
消息 207,级别 16,状态 1,第 3 行
列名 'Sg_KeepersResultLog' 无效。
where not exists
(select 1 from Sg_KeepersResultLog where FContent=a.FContent
and FId<a.FId)
select * from Sg_KeepersResultLog a
where not exists
(select 1 from Sg_KeepersResultLog where ResultType=a.ResultType
and FId<a.FId)这样只查了二条出来FId FContent ResultType
----------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------
1 22221 0
2 2222 0
3 2222 0
4 2222 0
5 3333 1
6 22221 0
7 2222 0
8 2222 0
9 2222 0
10 5555 1(10 行受影响)FId FContent ResultType
----------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------
1 22221 0
5 3333 1(2 行受影响)
where not exists
(select 1 from Sg_KeepersResultLog where ResultType=a.ResultType
and FId=a.FId-1)
ResultType相同时取fid连续值下的最小的不就是了。