现有表数据
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

解决方案 »

  1.   

     select * from Sg_KeepersResultLog a
     where not exists 
     (select 1 from Sg_KeepersResultLog where Sg_KeepersResultLog=a.Sg_KeepersResultLog
           and FId<a.FId)
      

  2.   

    哥 好像出错 消息 207,级别 16,状态 1,第 3 行
    列名 'Sg_KeepersResultLog' 无效。
    消息 207,级别 16,状态 1,第 3 行
    列名 'Sg_KeepersResultLog' 无效。
      

  3.   

     select * from Sg_KeepersResultLog a
     where not exists 
     (select 1 from Sg_KeepersResultLog where FContent=a.FContent
           and FId<a.FId)
      

  4.   


    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 行受影响)
      

  5.   

    select * from Sg_KeepersResultLog a
     where not exists 
     (select 1 from Sg_KeepersResultLog where ResultType=a.ResultType
           and FId=a.FId-1)
      

  6.   


    ResultType相同时取fid连续值下的最小的不就是了。