大家帮忙看看这个SQL语句怎么写?

byebye8742 2003-03-24 09:12:17
要用另外一个搜索条件作为排序的字段,我随便写一个肯定不对的,大家改正一下:
select * from article order by (select ontime from article where id=前面一个select里面的id)
我说明一下为什么要这么做,是因为一个论坛回复的帖子和发表的帖子都是放在一个表中的,唯一的区别就是如果是帖子的话fatherarticleid=0,是回复的话fatherarticleid=帖子的id,如果我要按照回复排序是不是就要让排序的字段是回复(where fatherarticleid=帖子的id)的time,究竟怎么做呢?
如果不能在一局sql语句里面表达清楚,大家想象其他办法
...全文
63 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
yonghengdizhen 2003-03-25
  • 打赏
  • 举报
回复
select a.*,b.* from article a join article b on a.id=b.fatherarticleid and a.fatherarticleid=0 order by b.ontime
byebye8742 2003-03-24
  • 打赏
  • 举报
回复
exec="select *from article AS A where fatherarticleid=-1 order by (select ontime from article AS B where A.articleid=B.fatherarticleid)"
是这句话的意思
是按照回复的ontime排序而回复就是articleid=fatherticleid
byebye8742 2003-03-24
  • 打赏
  • 举报
回复
正确的怎么写呢?
yonghengdizhen 2003-03-24
  • 打赏
  • 举报
回复
select a.*,b.* from article a join article b on a.id=b.fatherarticleid and a.fatherarticleid=0 order by a.ontime,b.ontime

看你的目的是为了按原贴和回贴时间进行排序
czp98069806 2003-03-24
  • 打赏
  • 举报
回复
你那个根本上行不通的
byebye8742 2003-03-24
  • 打赏
  • 举报
回复
好人作到第啊,大家再看看
byebye8742 2003-03-24
  • 打赏
  • 举报
回复
还是不队,大家看看有什么错误
exec="select *from article AS A where fatherarticleid=-1 order by (select ontime from article AS B where A.articleid=B.fatherarticleid)"
xiwanghope 2003-03-24
  • 打赏
  • 举报
回复
同意上面的做法~
cpp2017 2003-03-24
  • 打赏
  • 举报
回复
select * from arcticle AS A order by (select ontime from arctive where id=A.id)
book523 2003-03-24
  • 打赏
  • 举报
回复
select a.* from table1 a,table2 b where
a.id=b.id order by b.ontime

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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