今天做项目的时候遇到这样一个问题:
项目中执行sql语句,报错,说是没有M.id这个列。
sql语句:
select distinct M.[id],M.[book_id],M.[mark_title],M.[mark_content],M.[type],
M.[chapter_id],M.[chapter_filename],M.[filename],M.[create_time],M.[param1],M.[param2],
M.[numchapter],M.[flag],M.[extra],N.[numchapter]
from
(select A.[id],A.[book_id],A.[mark_title],A.[mark_content],A.[type],
A.[chapter_id],A.[chapter_filename],A.[filename],A.[create_time],B.[param1],B.[param2],
A.[numchapter],A.[flag],A.[extra]
from book_new_mark A left join book_mark_rowindex B
on (A.[book_id] = B.[book_id] or A.[filename] = B.[book_id]) and A.[type] = B.[type]
and (A.[extra] = B.[account] or ((A.[extra] is null or A.[extra] = '')
and(B.[account] is null or B.[account] = ''))) order by A.[create_time],A.[id] asc) M left join book_case N
on M.[book_id] = N.[bookid]
但是我在SQLite工具上测试sql可用,而且应用上也有类似的语句成功运行。
我折腾了半天,最后改成这样:
select distinct M.id,M.book_id,M.mark_title,M.mark_content,M.type,M.chapter_id,M.chapter_filename,
M.filename,M.create_time,M.param1,M.param2, M.numchapter,M.flag,M.extra,N.numchapter
from
(select *
from book_new_mark A left join book_mark_rowindex B
on (A.book_id = B.book_id or A.filename = B.book_id)
and A.type = B.type and (A.extra = B.account or ((A.extra is null or A.extra = '')
and(B.account is null or B.account = ''))) order by A.create_time,A.id asc) M left join book_case N
on M.book_id = N.bookid
这样就可以了,我怀疑是因为长度问题,但是搜了一下没有说明,执行sql方法的API也没有说明。求大拿说明?