首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

一个困扰小弟我很久的论坛查询SQL语句

2012-01-19 
一个困扰我很久的论坛查询SQL语句我做了一个论坛想查出最初发贴主题,阅读次数,回复次数,最后发表人,最后发

一个困扰我很久的论坛查询SQL语句
我做了一个论坛   想查出   最初发贴主题,阅读次数,回复次数,最后发表人,最后发贴时间。

我有个主贴表:mainNoteID   主贴ID,topic   主题,subjectmatter   内容,sendtime   发贴时间,replynum   回复次数,visitnum   访问次数,senduserID   发贴人
回贴表:   replynoteid   回贴ID,mainnoteID   主贴ID,topic   回贴主题,subjectmatter   回贴内容,userID   回贴人,replytime   回贴时间。

同时我发贴的时候,同时写入回贴表,把发的主贴作为回贴的第一条数据,为个方便计算楼层数。

请高手赐教,谢谢了

[解决办法]
select a.*,b.userID ,b.replytime
from 主贴表 a
join 回帖表 b on a. mainNoteID = b.mainnoteID
where not exists(select 1 from 回帖表 where mainNoteID = b.mainNoteID
and b.replytime < replytime )
[解决办法]
select a.topic,a.visitnum,a.replynum,b.userID ,b.replytime
from 主贴表 a,回帖表 b
where a. mainNoteID = b.mainnoteID
and not exists(select * from 回帖表 where mainNoteID = b.mainNoteID
and b.replytime < replytime )

热点排行
Bad Request.