我正在尝试计算查询返回的行数,其中包括Sum,Match,Bill和Group By语句。
我编写了一条SQL语句,该语句对搜索索引表执行查询,然后对结果进行分组。
我正在尝试计算结果,以便可以设置分页。
每当我以前使用过Count功能时,就是要对表中的行进行计数,而不是对查询结果进行计数。
此后,我还使用SELECT FOUND_ROWS()探索了SQL_CALC_FOUND_ROWS选项,但是我没有得到所需的结果。
搜索查询...
SELECT *, SUM(MATCH(`Field1`, `Field2`, `Field3`, `Field4`) AGAINST('test' IN BOOLEAN MODE)) as score FROM `search_index` WHERE MATCH(`Field1`, `Field2`, `Field3`, `Field4`) AGAINST('test' IN BOOLEAN MODE) GROUP BY `Field1`, `Field2` ORDER BY score DESC;
尝试次数1 ...
SELECT COUNT(*), SUM(MATCH(`Field1`, `Field2`, `Field3`, `Field4`) AGAINST('test' IN BOOLEAN MODE)) as score FROM `search_index` WHERE MATCH(`Field1`, `Field2`, `Field3`, `Field4`) AGAINST('test' IN BOOLEAN MODE) GROUP BY `Field1`, `Field2`
计数尝试2 ... (基于这篇文章How can I count the numbers of rows that a mysql query returned?)
SELECT SQL_CALC_FOUND_ROWS *, SUM(MATCH(`Field1`, `Field2`, `Field3`, `Field4`) AGAINST('test' IN BOOLEAN MODE)) as score FROM `search_index` WHERE MATCH(`Field1`, `Field2`, `Field3`, `Field4`) AGAINST('test' IN BOOLEAN MODE) GROUP BY `Field1`, `Field2`;
SELECT FOUND_ROWS();
尝试1-我要寻找的结果是89,但返回了89行,每行计数为1。
尝试2-我要寻找的结果是89,但是返回1行,计数为1。
任何建议将不胜感激!