0

嗨,我有一个 mysql 查询,它计算表中的行以进行分页,但我还需要计算并按另一列分组。

我可以让查询对记录进行分组并显示正确的结果,但它会阻止分页工作。

这是我的查询

SELECT 
   COUNT(*) as num, 
   COUNT (search_term)  
FROM $tableName 
WHERE client_id = '{$client_id}' 
AND search_term IS NOT NULL 
AND search_term != '' 
GROUP BY search_term

任何指针将不胜感激

4

1 回答 1

0

试试喜欢

SELECT COUNT(*) as num1, COUNT (search_term) as num2  
FROM $tableName 
WHERE client_id = '{$client_id}' 
    AND search_term IS NOT NULL 
    AND search_term != '' 
GROUP BY search_term
LIMIT $page , $limit

并且您需要将$page值作为当前页码,并且$limit将是一页包含的限制

于 2013-07-03T09:37:43.653 回答