取新闻最后回复时间新闻表有以下字段newsID //新闻标题newsTitle //标题createDate //发表时间......恢复表有一下字段newsRID //评论IDnewsID //所属新闻reTime //回复时间循环新闻列表的时候怎么取出每条新闻最后的评论的回复时间,只用SQL可以完成吗? [解决办法]可以。代码大致如下:
with table as( select newsID, max(reTime) as maxTime from 恢复表 )select * from 新闻表inner join table on table.newsID = 新闻表.newsID
可以。代码大致如下:SQL codewith table as( select newsID, max(reTime) as maxTime from 恢复表 )select * from 新闻表inner join table on table.newsID = 新闻表.newsID