0

这是我的表结构:

session_id | session_name |  celebrity_id | charity_id | created_date

我想获得与charity_id 关联的名人ID 的总数。现在,名人 ID 可以针对同一个慈善 ID 多次出现在表中,这是我在此处编写的 SQL,$member_id是我在 PHP 脚本中提供的慈善 ID:

SELECT COUNT(celebrity_id) AS count 
FROM sessions
WHERE chairty_id = $member_id
GROUP BY celebrity_id,charity_id

但它返回我很多行,而不是只返回一个计数。

4

2 回答 2

2

只需使用:

SELECT COUNT(celebrity_id) AS count 
FROM sessions
WHERE chairty_id = $member_id
于 2013-05-17T09:43:36.473 回答
0

不要使用 GROUP BY celebrity_id

SELECT COUNT(celebrity_id) AS count 
FROM sessions
WHERE chairty_id = $member_id

GROUP BYcharity_id

高温高压

编辑:@Veekay 搞定了,你根本不需要分组。

于 2013-05-17T09:43:34.290 回答