這裏的工作正常的查詢:SQLite的說:「沒有這樣的列:的rowid」使用子查詢時
SELECT rowid as msg_rowid, a, b, c FROM messages m1
這裏還有另外一個,也是罰款:
SELECT rowid as match_rowid FROM messages m2 WHERE x LIKE '%abc%'
但如果我把在一起如下,SQLite的抱怨:
SELECT rowid as msg_rowid, a, b, c FROM messages m1
JOIN
(SELECT rowid as match_rowid FROM messages m2 WHERE x LIKE '%abc%')
ON
msg_rowid >= match_rowid - 10 AND msg_rowid <= match_rowid + 5
給予什麼樣子了誤導性的錯誤消息:No such column: rowid
。
我該如何解決這個問題?
查詢運行正常,如果我使用一個messages.timestamp場,而不是ROWID的:
SELECT timestamp as msg_ts, a, b, c FROM messages m1
JOIN
(SELECT timestamp as match_ts FROM messages m2 WHERE x LIKE '%abc%')
ON
msg_ts >= match_ts - 10 AND msg_ts <= match_ts + 5
這是一個錯誤,或者對使用rowid
一個由設計限制?
你可以嘗試在子查詢中別名rowid嗎? 像這樣:SELECT m2.rowid as match_rowid FROM messages m2 WHERE x LIKE'%abc%' – GuZzie 2011-12-30 18:13:24
@GuZzie Whoa ...在*子查詢中別名*沒有幫助,但別名*只是*外部的,因爲'm1.rowid',修復它! – 2011-12-30 18:27:46
太棒了! :D很高興聽到你解決了這個問題 – GuZzie 2012-01-01 19:33:30