小说     表--------------------------------id   小说名称
1    谈谈性恋恋爱
2    我是怎么泡上校花的
3    养个女儿做老婆
4    我的美女老总
5    和校花同居的日子
章节     表
---------------------------------
id  章节名称              小说编号    章节时间
1   男人与狗不得进入        1
2   我成熟了                1
3   第30节 日记             1
4   与校花的初识            2
5   与校花花生关系          2
6   第一章 浴室的雾气很浓   3 
7   第一章                  5
8   第二章                  5
9   第216章 侠影飞飞        3
10  我的美女老总1          4
显示校效果
小说名称              小说章节 
我的美女老总          我的美女老总1
养个女儿做老婆        第216章 侠影飞飞
和校花同居的日子      第二章 
我是怎么泡上校花的    与校花花生关系
谈谈性恋恋爱          第30节 日记显示最近更新的小说.并只显示当篇小说最新一章节

解决方案 »

  1.   

    先从章节表中查出最新章节
    select 章节名称,小说编号 from 章节 a 
    where not exists(
     select 1 from 章节 where 小说编号 = a.小说编号 and id>a.id)
      

  2.   

    select 
    a.小说名称,b.章节名称
    from 章节 a
    inner join 表 b
    on a.小说编号=b.id
    where b.小说编号 in(select top 1 小说编号 from 章节 c where a.id=c.小说编号 order by 单节时间 desc)
      

  3.   

    郁闷 csdn上面今天感觉好卡...
      

  4.   


    --> 测试数据: @小说
    declare @小说 table (id int,小说名称 varchar(18))
    insert into @小说
    select 1,'谈谈性恋恋爱' union all
    select 2,'我是怎么泡上校花的' union all
    select 3,'养个女儿做老婆' union all
    select 4,'我的美女老总' union all
    select 5,'和校花同居的日子'
    --> 测试数据: @章节
    declare @章节 table (id int,章节名称 varchar(50),小说编号 int,章节时间 int)
    insert into @章节
    select 1,'男人与狗不得进入',1,null union all
    select 2,'我成熟了',1,null union all
    select 3,'第30节 日记',1,null union all
    select 4,'与校花的初识',2,null union all
    select 5,'与校花花生关系',2,null union all
    select 6,'第一章 浴室的雾气很浓',3,null union all
    select 7,'第一章',5,null union all
    select 8,'第二章',5,null union all
    select 9,'第216章 侠影飞飞',3,null union all
    select 10,'我的美女老总1',4,null
    select 小说名称,b.章节名称 from @小说 a left join 
    (select * from @章节 a where not exists(select 1 from @章节 where 小说编号=a.小说编号 and id>a.id))b
    on a.id=b.小说编号
      

  5.   


    USE 小说库;
    GO 
    CREATE TABLE TMP_ZJ 
    AS select 章节名称,小说编号 from 章节 a 
      where not exists( 
             select 1 from 章节 where 小说编号 = a.小说编号 and id>a.id
             );
    SELECT 小说名称,TMP_ZJ  from 小说,章节 where 小说.小说id = TMP_ZJ .小说编号;
    GO 
    DROP TABLE TMP_ZJ;
    GO这样行不行一句写出来就的用inner join了
      

  6.   

    好像写错了....
    declare @t table(id int,小说名称 varchar(128))
    insert into @t
    select '1','谈谈性恋恋爱'
    union all
    select '2','我是怎么泡上校花的'
    union all
    select '3','养个女儿做老婆'
    union all
    select '4','我的美女老总'
    union all
    select '5','和校花同居的日子'declare @tb table(id int identity(1,1),单节名称 varchar(512),小说编号 int,单节时间 datetime)insert into @tb
    select '男人与狗不得进入','1',dateadd(d,1,getdate())
    union all
    select '我成熟了','1',dateadd(d,2,getdate())
    union all
    select ' 第30节 日记','1',dateadd(d,3,getdate())
    union all
    select '与校花的初识','2',dateadd(d,4,getdate())
    union all
    select '与校花花生关系','2',dateadd(d,5,getdate())
    union all
    select '第一章 浴室的雾气很浓','3',dateadd(d,6,getdate())
    union all
    select '第一章','5',dateadd(d,7,getdate())
    union all
    select '第二章','5',dateadd(d,8,getdate())
    union all
    select '第216章 侠影飞飞','3',dateadd(d,9,getdate())
    union all
    select '我的美女老总1','4',dateadd(d,10,getdate())select 
    *
    from @t a
    inner join @tb b
    on a.id=b.小说编号
    where b.id in(select top 1 id from @tb c where b.小说编号=c.小说编号 order by c.单节时间 desc)
      

  7.   

                select top 13 b.list_name,a.view_type,a.view_id,a.id  from (select * from list_view c where not exists(select 1 from list_view where view_id = c.view_id and id>c.id)) a left join list_book b on a.view_id=b.id order by a.id desc
    这个运行可以了
      

  8.   

    www.2du8.com 爱读吧小说网  现在弄好了..