TABLE1 字段 id name, Content ,photo,count(--点击--) classid,table2 字段classid,classname
第一 我要查询select name ,content,photo count点击率最好高的一条数据 where 给出了Classname 的vlaues
第二 要查询内容一样,条件一样,只是我这次要差除了第一条之外,从第2条数据开始取依次取几条我自己写了好长时间,还是报错
谢谢各位大虾
第一 我要查询select name ,content,photo count点击率最好高的一条数据 where 给出了Classname 的vlaues
第二 要查询内容一样,条件一样,只是我这次要差除了第一条之外,从第2条数据开始取依次取几条我自己写了好长时间,还是报错
谢谢各位大虾
解决方案 »
- SQL中写循环语句的问题
- CONTAINS(INFOR, '清原有*') 为什么没有CONTAINS(INFOR, '清原*')查询的结果多呢
- 无法打开备份设备 'E:\gts\admin\database\20080304.bak'。出现操作系统错误 3(系统找不到指定的路径。)。
- 数据库 存储过程
- 请大家看看SQL和C语言的混合算法怎么翻译为SQL?、
- 用户'sa'登录失败
- 如何用ALTER TABLE去掉一字段的默认值属性
- 我无法在企业管理器中注册本机上的一个 sql server 是怎么一回事啊?
- 求触发器
- 一个很简单的问题!
- 问一条比较难的sql语句
- UPDATE OPENROWSET 带条件的的SQL语句如何写
--第一:没看看懂你的count(--点击--)
--不知是不是?
select id name, Content ,photo,max(count(--点击--)), classid
from TABLE1 a join table2 b on a.classid = b.classid
where b.Classname = ?
--最好给点实例数据
from VodInfo t1
inner join VodClass t2
on t1.VodClass= t2.ClassId
where t2.GroupName= @GroupName
order by VodCount desc
(
@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 子句。
(
@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子句了
第2问题是 比如count这个字段是点击率,本来查询结果这样本来排序下来是10,9,8,7,6,5,4,3,2,1
但是我现在要这个的结果,我不要10,想从9开始,到1 条件如上,还是groupname谢谢各位大虾---------^ _ ^
from VodInfo t1
inner join VodClass t2
on t1.VodClass= t2.ClassId
where t2.GroupName= @GroupName
order by t1.VodCount desc
第2问题是 比如count这个字段是点击率,本来查询结果这样本来排序下来是10,9,8,7,6,5,4,3,2,1
但是我现在要这个的结果,我不要10,想从9开始,到1 条件如上,还是groupname 谢谢各位大虾---------^ _ ^
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没有进行调试的,运行效率不是很高`
主要对楼主的要求不是很明白,强烈建议楼主恶补语文
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