新闻表有以下字段
newsID //新闻标题
newsTitle //标题
createDate //发表时间
......
恢复表有一下字段
newsRID //评论ID
newsID //所属新闻
reTime //回复时间
循环新闻列表的时候怎么取出每条新闻最后的评论的回复时间,只用SQL可以完成吗?
------解决方案--------------------
可以。
代码大致如下:
with table as
(
select newsID, max(reTime) as maxTime
from 恢复表
)
select * from 新闻表
inner join table on table.newsID = 新闻表.newsID
------解决方案--------------------
在1楼给你的是sql语句。
你可以保存为存储过程。然后在asp.net 中执行存储过程就能返回结果集了。
------解决方案--------------------
错了好不好
with table as
(
select newsID, max(reTime) as maxTime
from 恢复表 group by newsID
)
select * from 新闻表
inner join table on table.newsID = 新闻表.newsID
------解决方案--------------------
SqlCommand com = new SqlCommand(Sql语句);
object time=com.ExecuteScalar();
return sTail.ToString();