0
我正在嘗試使用Postgres直接使用Postgres而不是某些命令語言擴展來查找帶有彼此雙目詞的句子。我的表是:如何引用子查詢中的當前搜索結果
TABLE word (
spelling text,
wordid serial
)
TABLE sentence (
sentenceid serial
)
TABLE item (
sentenceid integer,
position smallint,
wordid integer
)
我有一個簡單的查詢,以找到一個詞的句子:通過其相應的項目都有一個項目裏有些字
SELECT DISTINCT sentence.sentenceid
FROM item, word, sentence
WHERE
word.spelling = 'word1' AND
item.wordid = word.wordid AND
sentence.sentenceid = item.sentenceid
和我要的是過濾,反過來.sentenceid =當前查詢結果的項目(或句子).sentenceid和 item.position =當前查詢結果的item.position + 1
我沒有看到ALIAS的工作,也不知道如何引用子查詢中查詢的當前狀態。
您可以添加一些示例數據和預期的輸出嗎?我很難理解「當前查詢結果的位置」和「當前查詢結果的位置+1」是什麼意思。它聽起來像是在尋找'lead()'或'lag()'函數 –