[英]Two Counts in a MYSQL Query
Hi I have a mysql query which counts the rows in the table for pagination, but I also need to count and group by another column. 嗨,我有一个mysql查询,它计算表中的行以进行分页,但是我还需要对另一列进行计数和分组。
I can get the Query to group the records and show correct results, but it stops the pagination from working. 我可以通过查询对记录进行分组并显示正确的结果,但是它使分页无法正常工作。
This is my Query 这是我的查询
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
Any pointers would be appreciated 任何指针将不胜感激
Try like 尝试像
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
And you need to give $page
value as the current page number and $limit
will be the limit that one page contains 并且您需要提供
$page
值作为当前页码,而$limit
将是一页包含的限制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.