读书人

Aceess 查询语句有关问题

发布时间: 2013-01-06 15:44:48 作者: rapoo

Aceess 查询语句问题
新闻表A

id title content addtime

评论表B

id articleid conent username addtime

--------------------------------------

注意:B表中的articleid 对应A表中的id

目的:查询近一个月时间内评论做多的新闻所有信息及该条新闻的评论总数


access数据库

[解决办法]
select * from 表A where id=(select top 1 articleid from 表B group by articleid order by count(*) desc)
[解决办法]

引用:
还缺个时间条件,
自然月:where datediff('w',addtime,now())=0
30天内:where dat……

写错了,第二个where条件应该是<30
[解决办法]
select top 5 A.*,B.total from 表A as a left join (select articleid,Count(articleID) as total from 表B group by articleid) as b on a=id.b.articleid order by B.total desc
[解决办法]
引用:
select top 5 A.*,B.total from 表A as a left join (select articleid,Count(articleID) as total from 表B group by articleid) as b on a=id.b.articleid order by B.total desc

等号位置是不是错啦,
on a.id=b.articleid
还有时间限制
where datediff('d',a.addtime,now())<30

读书人网 >asp.net

热点推荐