SELECT
`list_type`.`type`
FROM
`events`
INNER JOIN
`list_type` ON `events`.`type` = `list_type`.`id`
WHERE
`events`.`date` BETWEEN '2012-01-01' AND '2012-12-31'
AND `events`.`center_id` = 2
GROUP BY `events`.`name`
Baseline
Baseline
Baseline
Baseline
Baseline
Baseline
Baseline
Special Events
Special Events
Special Events
但我希望它像这样计算每种类型
Baseline 7
Special Events 3
所以我尝试了这个
SELECT
`list_type`.`type`,
COUNT(*)
FROM
`events`
INNER JOIN
`list_type` ON `events`.`type` = `list_type`.`id`
WHERE
`events`.`date` BETWEEN '2012-01-01' AND '2012-12-31'
AND `events`.`center_id` = 2
GROUP BY `events`.`name`
但它给了我这个:
Baseline 45
Baseline 3
Baseline 56
Baseline 23
Baseline 12
Baseline 9
Baseline 2
Special Events 5
Special Events 4
Special Events 18
它正在计算每个名称和类型的数量,而不是输出表单查询。我也试过 COUNT( list_type
. type
) 谢谢你的帮助。