0
請幫助我將以下SQL查詢轉換爲Solr查詢。需要幫助將SQL查詢轉換爲Solr查詢
SELECT PolicyNumber,EndorsementNumber
FROM Policy_Core a
WHERE AgencyCode = '500'
AND PolicyNumber = 5201070001753
AND EndorsementNumber = (SELECT MAX (EndorsementNumber)
FROM Policy_Core b
WHERE a.PolicyNumber = b.PolicyNumber).
我在Solr服務器中有一個內核具有以下結構。
id (Unique ID) PolicyNumber(Number), EndorsementNumber(Number), AgencyCode(Number)
5201070001753-1 5201070001753 ,1 ,500
5201070001753-2 5201070001753 ,2 ,500
5201070001753-3 5201070001753 ,3 ,500
5201070001753-4 5201070001753 ,4 ,100
5201070001753-5 5201070001753 ,5 ,100
我準備了以下Solr查詢。
http://localhost:8983/solr/db/select?q=PolicyNumber:5201070001753 AND AgencyCode:500 &fq={!collapse field=PolicyNumber max=EndorsementNumber}
這會返回錯誤的結果(因爲它正在做結果分組)。根據定義的核心記錄,我期待Null/No結果,但是我得到一個記錄,其中EndorsementNumber no 3。 Solr執行以下查詢。我需要幫助創建solr查詢以使Joel POlicy核心與它自己一起獲得PolicyNumber的max EndorsementNumber
SELECT PolicyNumber,EndorsementNumber
FROM Policy_Core a
WHERE AgencyCode = '500'
AND PolicyNumber = 5201070001753
GROUP BY PolicyNumber,EndorsementNumber HAVING EndorsementNumber = MAX(EndorsementNumber)
你看着這個鏈接? https://wiki.apache.org/solr/Join檢查「與SQL比較」部分 – jay 2014-10-06 00:42:01