TABLE1 字段 id name, Content ,photo,count(--点击--) classid,table2 字段classid,classname
第一 我要查询select name ,content,photo count点击率最好高的一条数据 where 给出了Classname 的vlaues
第二 要查询内容一样,条件一样,只是我这次要差除了第一条之外,从第2条数据开始取依次取几条我自己写了好长时间,还是报错
谢谢各位大虾

解决方案 »

  1.   

    表结构写得太乱了,整理一下再发一次吧另外,把你写的SQL也贴出来,帮你改改就是了
      

  2.   

     
    --第一:没看看懂你的count(--点击--)
    --不知是不是?
    select id name, Content ,photo,max(count(--点击--)), classid
    from TABLE1 a join table2 b on a.classid = b.classid
    where b.Classname = ?
    --最好给点实例数据
      

  3.   

     select VodName  max(VodCount)from VodInfo where VodClass=(select ClassId from VodClass where GroupName=@GroupName) GROUP BY(VodName)desc我想查点击率MAX(VodCOUNT)
      

  4.   

    select top 1 t1.VodName  ,t1.VodCount
    from VodInfo t1 
    inner join VodClass t2
    on t1.VodClass= t2.ClassId 
    where t2.GroupName= @GroupName
    order by VodCount desc
      

  5.   

    create proc proc_Cinema_Head
    (
    @GroupName varchar(50)
    )
    as
    select VodName,VodContent,VodUpPhoto,max(VodCount) from VodInfo A join VodClass B on A.VodClass = b.ClassId Where GroupName=@GroupName报错列 'A.VodName' 在选择列表中无效,因为该列未包含在聚合函数中,并且没有 GROUP BY 子句。
    服务器: 消息 8118,级别 16,状态 1,过程 proc_Cinema_Head,行 6
    列 'A.VodContent' 在选择列表中无效,因为该列未包含在聚合函数中,并且没有 GROUP BY 子句。
    服务器: 消息 8118,级别 16,状态 1,过程 proc_Cinema_Head,行 6
    列 'A.VodUpPhoto' 在选择列表中无效,因为该列未包含在聚合函数中,并且没有 GROUP BY 子句。
      

  6.   

    create proc proc_Cinema_Head 

    @GroupName varchar(50) 

    as 
    select VodName,VodContent,VodUpPhoto,max(VodCount) from VodInfo A join VodClass B on A.VodClass = b.ClassId Where GroupName=@GroupName 
    group by VodName,VodContent,VodUpPhoto --你忘记加GROUP BY子句了
      

  7.   

    哈哈,第一个问题解决了
    第2问题是 比如count这个字段是点击率,本来查询结果这样本来排序下来是10,9,8,7,6,5,4,3,2,1
    但是我现在要这个的结果,我不要10,想从9开始,到1 条件如上,还是groupname谢谢各位大虾---------^ _ ^
      

  8.   

    select top 1 t1.VodName ,t1.VodContent,t1.VodUpPhoto ,t1.VodCount
    from VodInfo t1 
    inner join VodClass t2
    on t1.VodClass= t2.ClassId 
    where t2.GroupName= @GroupName
    order by t1.VodCount desc
      

  9.   

    哈哈,第一个问题解决了 
    第2问题是 比如count这个字段是点击率,本来查询结果这样本来排序下来是10,9,8,7,6,5,4,3,2,1 
    但是我现在要这个的结果,我不要10,想从9开始,到1 条件如上,还是groupname 谢谢各位大虾---------^ _ ^
      

  10.   

    select VodName,VodContent,VodUpPhoto,max(VodCount) as VodCount
    from VodInfo A 
    join VodClass B 
    on A.VodClass = b.ClassId 
    Where GroupName=@GroupName
    and A.VodClass is not exists
    (
    select top 1 id,max(VodCount) as VodCount
    from VodInfo A 
    join VodClass B 
    on A.VodClass = b.ClassId 
    Where GroupName=@GroupName 
    )这段SQL没有进行调试的,运行效率不是很高`
    主要对楼主的要求不是很明白,强烈建议楼主恶补语文
      

  11.   

    use test
    go
    if object_id('tba') is not null
    drop table tba
    go
    create table tba(id int,name varchar(10))
    insert into tba select 1,'a'
    insert into tba select 2,'a'
    insert into tba select 3,'a'
    insert into tba select 4,'a'
    insert into tba select 5,'a'
    insert into tba select 6,'a'
    insert into tba select 7,'a'
    insert into tba select 8,'a'
    insert into tba select 9,'a'
    insert into tba select 10,'a'
    select top 4 *
    from (select top 5 *
    from tba
    ) a
    order by id desc
    5 a
    4 a
    3 a
    2 a