+ -
当前位置:首页 → 问答吧 → sql语句

sql语句

时间:2011-11-25

来源:互联网

select 
  (select substr(t.tojid,0,5) as tojid from 
  (select c.tojid
  from ofmessagearchive c
  where c.conversationid = 66
  order by c.sentdate) t where rownum = 1) as tojid,
a.* from ofConversation a, ofuser b
 where a.username = b.username
  and a.conversationid = 66;
这样写就是我要的效果

  select 
  (select substr(t.tojid,0,5) as tojid from 
  (select c.tojid
  from ofmessagearchive c
  where c.conversationid = a.conversationid
  order by c.sentdate) t where rownum = 1) as tojid,
a.* from ofConversation a, ofuser b
 where a.username = b.username
  and a.conversationid = 66;
这样写就报错,请问该如何写那?

作者: Adminduan   发布时间: 2011-11-25

报什么错了?

作者: cosio   发布时间: 2011-11-25

下面那个恐怕要写成left join了吧

作者: humalonginus   发布时间: 2011-11-25

引用 1 楼 cosio 的回复:

报什么错了?


他是弹出框来。写到 ORA-00904:"A","CONVERSATIONID":invalid identifier

作者: Adminduan   发布时间: 2011-11-25

A.CONVERSATIONID 别名的定义有问题!自己查一下!

作者: cosio   发布时间: 2011-11-25

引用 4 楼 cosio 的回复:

A.CONVERSATIONID 别名的定义有问题!自己查一下!


他不是别名的问题吧,我看了看,可能是因为他执行的先后顺序不一样导致的错误,应该的先执行where c.conversationid = a.conversationid 但是在执行这个的时候 a.conversationid并没有值,所以报错,这是我的自我感觉,不知道对不?如果对还请帮忙看看应该如何修改那?

作者: Adminduan   发布时间: 2011-11-25

引用 2 楼 humalonginus 的回复:

下面那个恐怕要写成left join了吧


我试了试,还是那个错误。
这个好像跟left join没有什么关系吧

作者: Adminduan   发布时间: 2011-11-25

热门下载

更多