将当日的新闻分类,按照新闻分类下新闻的总数降序排列,sql语句怎么写?

来源:百度知道 编辑:UC知道 时间:2024/09/22 18:22:18
select count(*) as flag,id,nTitle from News where convert(varchar(10),[time],120)=convert(varchar(10),getdate(),120) group by classId order by flag desc
选择列表中的列 'News.id' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。应该怎么解决!

假定新闻表中一条记录代表一个新闻:

select b.分类, count(*) as 新闻总数
from 新闻表 a
left join 新闻分类表 b on a.分类ID=b.ID
where 新闻时间 between substring(convert(varchar, getdate(), 120), 1, 10) and
substring(convert(varchar, dateadd(day, 1, getdate()), 120), 1, 10)
group by b.分类
order by 新闻总数 desc

select count(*) as flag,id,nTitle from News where convert(varchar(10),[time],120)=convert(varchar(10),getdate(),120) group by classId,id,ntitile order by flag desc

这个问题您有点没说清楚。就是 新闻分类下的新闻是另外一个表还是在同一个表中?这个很重要

那你要把两个表的表结构给出来