求一条SQL

ssc752000322 2010-03-21 02:46:27
mysql数据库
问题表(question),回答表(answer)他们里面都有一个time列,要找出问题表中的数据和回答表只“最新”回复的数据,并且按两个表的时间排序。补充一下,只要回答表最新的回复,别的过滤掉,另外,问题可能没有回答。对应字段是回答表里有其回答问题的ID
如question表 answer表
question_id question_time 丨 answer_id answer_time answer_questionid
1 2010-03-21 13:46:42 丨 1 2010-03-21 13:49:42 1
2 2010-03-21 13:48:42 丨 2 2010-03-21 13:52:42 1
3 2010-03-21 13:58:42 丨 3 2010-03-21 13:49:49 2
4 2010-03-21 13:60:42 丨
我要的结果是
question_id question_time answer_id answer_time answer_questionid
4 2010-03-21 13:60:42
3 2010-03-21 13:58:42
1 2010-03-21 13:46:42 2 2010-03-21 13:52:42 1
2 2010-03-21 13:48:42 3 2010-03-21 13:49:49 2
因为2010-03-21 13:60:42>2010-03-21 13:58:42>2010-03-21 13:52:42>2010-03-21 13:49:49

...全文
102 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssc752000322 2010-03-21
  • 打赏
  • 举报
回复
我改了结构,这种本来就不是很科学,效率太低了,谢谢了,加分。。。。
看了一下你的SQL,好像也不行哦。。。。
ruohai9111 2010-03-21
  • 打赏
  • 举报
回复
select * from (select * from (select q.question_id q.question_time a.answer_id a.answer_time a.answer_questionid from question as q join answeras a on q.question_id=a.answer_questionid) order by question_time ) where distinct(question_id)
carat12 2010-03-21
  • 打赏
  • 举报
回复
菜鸟路过帮顶,期待大牛出现

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧