Sphinxsearch:1064无法使用属性与GROUP BY不相关的HAVING

时间:2019-05-27 05:15:20

标签: mysql sphinx

我正在使用示例sphinxsearch配置和版本3.1.1的下载随附的“测试”数据库

source src1
{
type            = mysql

sql_host        = localhost
sql_user        = root
sql_pass        =
sql_db          = test
sql_port        = 3306  # optional, default is 3306

sql_query       = \
    SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
    FROM documents

sql_attr_uint       = group_id
sql_attr_timestamp  = date_added
}

运行时:

$array = $sphinx->prepare("SELECT date_added,group_id FROM test1 GROUP BY group_id HAVING group_id > 1");
$array->execute();

我收到此错误:

SQLSTATE[42000]: Syntax error or access violation: 1064 can not use HAVING with attribute not related to GROUP BY

2 个答案:

答案 0 :(得分:2)

使用where condition代替having,因为您没有使用任何aggregation,在这种情况下也不需要group by

SELECT date_added,group_id 
FROM test1 
where group_id>1

答案 1 :(得分:1)

像这样使用:-

选择count(group_id)作为count,创建日期,test_group的group_id,按count> 1的group_id进行选择