select top n 是取查询结果的前 n 条记录,如果你的结果多于 30 条。那么用 select top 30 查到的结果就只是 30 条。

解决方案 »

  1.   

    我不失说这个
    我没有说清楚.
    是我之后加进去的新数据都不显示了很奇怪
    就是最新的lstcmt_date
      

  2.   

    top not in分页?感觉写的好别扭...
        select * from 
            (select top 30 
            [auto_tpc_id] 
            ,t.[flag] 
            ,[checkboxid] 
            ,[tpc_uid] 
            ,[tpc_nick] 
            ,[lstcmt_uid] 
            ,[lstcmt_nick] 
            ,[lstcmt_date] 
            ,[tpc_title] 
            ,[tpc_date] 
            ,[count_read] 
            ,[tpc_img] 
            ,count(c.[tpc_id]) as count_cmt 
            from [goodluck].[dbo].[topicInfo] as t 
            left join [goodluck].[dbo].[commentInfo] as c 
            on t.auto_tpc_id = c.[tpc_id] and c.[flag] = '0' 
            where t.flag = '0' 
            group by 
            [auto_tpc_id] 
            ,t.[flag] 
            ,[checkboxid] 
            ,[tpc_uid] 
            ,[tpc_nick] 
            ,[lstcmt_uid] 
            ,[lstcmt_nick] 
            ,[lstcmt_date] 
            ,[tpc_title] 
            ,[tpc_date] 
            ,[tpc_img] 
            ,[count_read] order by [lstcmt_date] desc--内联表加上排序
    ) as e 
            where flag = '0' AND e.[auto_tpc_id] 
            not in (select top 0 [auto_tpc_id] 
            from [goodluck].[dbo].[topicInfo] 
            where flag = '0' order by [lstcmt_date] desc) 
            order by [lstcmt_date] desc