0

我需要 AS 查询,但示例:

rat ='10' 或 rat >='10' 对于这个查询;

$minimalEntry = mysql_query("SELECT author,count(id) AS rat 
                               FROM sds_posts 
                           GROUP BY author 
                           ORDER BY rat ASC 
                              LIMIT 0,20");

谢谢你..

4

3 回答 3

2

你需要HAVING子句:

SELECT author, COUNT(id) AS rat 
FROM sds_posts 
GROUP BY author 
HAVING COUNT(id) >= 10
ORDER BY rat ASC 
  LIMIT 0,20
于 2012-12-28T00:14:42.120 回答
1

只需添加一个 WHERE 条件。

$minimalEntry = mysql_query("SELECT author,count(id) AS rat 
                             FROM sds_posts 
                             WHERE count(id)  >= 10 
                             GROUP BY author 
                             ORDER BY rat ASC 
                             LIMIT 0,20"
                           );

编辑:这是错误的。您需要在此查询中使用 HAVING 子句。

于 2012-12-27T23:55:34.423 回答
1

我会使用内部选择来避免计数聚合加倍:

SELECT author, rat
FROM
(
    SELECT author, count(id) AS rat
    FROM sds_posts
) 
WHERE rat >= 10
ORDER BY rat
LIMIT 0,20
于 2012-12-28T00:08:47.700 回答