每個ID我需要找到的最後5個結果(通過EVENTDATE訂購)從測試表找到最後一個5個結果(通過EVENTDATE訂購)爲表
每一個標識的表中的示例圖像結構下面這是隻顯示從1個ID記錄,其中有數以千計的不同ID的所有與時間不同的結果,因此爲什麼我只希望最後5要返回
我有以下數據查詢幾乎是正確的,但它包括num_result = 0和auditflag = 2的計數爲< 6 (這當然是記在我的代碼是,我是新手)
SELECT q1.id, q1.eventdate, q1.num_result " _
& "FROM test AS q1 INNER JOIN test AS q2 ON (q1.id = q2.id) " _
& "AND (q1.eventdate <= q2.eventdate) AND q1.auditflag=1 " _
& "WHERE q1.num_result > 0 " _
& "GROUP BY q1.id, q1.eventdate, q1.num_result " _
& "HAVING COUNT(*) < 6 " _
& "ORDER BY q1.id, q1.eventdate DESC
我只是想找到最後5個記錄是匹配即以黃色突出顯示 - 從那些具有num_result最後5個記錄> 0, auditflag = 1
SQL查詢是寫在Excel中使用VBA visoledb
我越來越與1號線的「翻譯錯誤這兩個查詢的錯誤消息。。?意外的符號 – BradleyS
@BradleyS是否指向查詢任何特別的地方沒有什麼明顯的錯誤,我可以看到 –
它必須是VBA或者與PG的visoledb連接,它不會接受要使用的代碼的某些元素,雖然感謝您的幫助,但我想我將不得不嘗試使用VBA來實現這一點 – BradleyS