declare @PageCount int,
@TopicId int,
@Num int
BEGIN
select
    distinct
    top 6 
t.topicid,
t.title,
isnull(t.pic,'../images/pic003.jpg') as pic
from 
dbo.T_Novel_Topic t,
    dbo.T_Books_Order o
    where 
    o.OrderType=2 and
    o.UserId in (select UserId from dbo.T_Books_Order where BooksId=1) and
    o.BooksId <> 1 and
    o.BooksId not in (select Top (6*0) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)) and
    o.BooksId=t.topicid and 
    o.Status=1   
   
END
红字的那个地方有问题呀 如果 6*1 显示的条数 跟6*2一样

解决方案 »

  1.   

    你自己作个测试就可以知道问题在哪了--测试1
    declare @PageCount int,
    @TopicId int,
    @Num int
    BEGIN
    select
      distinct
      top 6  
    t.topicid,
    t.title,
    isnull(t.pic,'../images/pic003.jpg') as pic
    from  
    dbo.T_Novel_Topic t,
      dbo.T_Books_Order o
      where  
      o.OrderType=2 and
      o.UserId in (select UserId from dbo.T_Books_Order where BooksId=1) and
      o.BooksId <> 1 and
    --  o.BooksId not in (select Top (6*0) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)) and
      o.BooksId=t.topicid and  
      o.Status=1   
        
    END
    --测试2
    select Top (6*1) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)--测试3
    select Top (6*2) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)
      

  2.   

    不好意思,没有看完整的代码
    应该是order by的问题
    加上order by BooksId 试试
      

  3.   

    你的 (select Top (6*1) BooksId from dbo.T_Books_Order where UserId in(select UserId from dbo.T_Books_Order where BooksId=1)) 
    里面有null值,任何数和null比较都是 false ,所以任何数都不回返回