1
我有一個查詢,我想運行相同的思維獅身人面像,但我有問題HAVING
子句。相關的代碼如下:正確的語法,以思維與獅身人面像HAVING
#technology_index.rb
has taggings.tag_id, :as => :tag_id
has id, :as => :technology_id
#technology.rb
search(params[:query],
with: { tag_id: params[:filter].values.flatten },
group_by: :technology_id,
having: "COUNT(`technology_id`)=#{params[:filter].size}"
)
這引發了我下面的錯誤(錯誤信息的新線是我的):
sphinxql: syntax error, unexpected IDENT, expecting '*' near '`technology_id`)=1 LIMIT 0, 20;
SHOW META' - SELECT *, groupby() AS sphinx_internal_group, id AS sphinx_document_id,
count(DISTINCT sphinx_document_id) AS sphinx_internal_count
FROM `technology_core` WHERE MATCH('fibrosis') AND `tag_id` IN (2)
AND `sphinx_deleted` = 0 GROUP BY `technology_id` HAVING COUNT(`technology_id`)=1
LIMIT 0, 20; SHOW META
問題是與having:
條款,因爲如果我刪除它,至少查詢起作用。 自從2.2.1 beta HAVING
is supported(使用2.2.6),the same for TS 3.1(使用3.1.2)推測。我在文檔中找不到任何信息about use of HAVING,但是如果我嘗試類似having: "COUNT(*)>1"
的作品,所以我想,我只是錯誤地調用它。什麼應該是使用TS的having:
的正確方法?
只是爲了清楚它的COUNT(列)不是由sphinx支持的 - 它實際上並沒有真正的NULL概念。但COUNT(*)有效。 (即,而不是HAVING的問題) – barryhunter 2014-12-05 13:51:58