-1

我想从我的表 tbl_itunes_report 中计算特定月份的数据。表结构是

id  int pimary key
provider_country   varchar(50)
title   varchar(50)
product_type_identifier varchar(50)
begin_date varchar(50)

这是我的查询

 SELECT 
 title,
 sum(CASE WHEN MONTH(begin_date)= '05' THEN 1 ELSE 0) as june
   FROM
 tbl_itunes_report
   WHERE
 `product_type_identifier` = '1T'
 group by title

但这个查询对我不起作用。有一个错误显示

 #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') as june FROM tbl_itunes_report WHERE `product_type_identifier` = '1T' group' at line 3

如果有人可以帮助我,请。提前致谢

4

2 回答 2

3

您在 CASE 语句的末尾缺少 END 关键字

SELECT 
 title,
 sum(CASE WHEN MONTH(begin_date)= '05' THEN 1 ELSE 0 END) as june
   FROM
 tbl_itunes_report
   WHERE
 `product_type_identifier` = '1T'
 group by title
于 2012-11-23T12:08:21.707 回答
2

你错过了END. 代替

sum(CASE WHEN MONTH(begin_date)= '05' THEN 1 ELSE 0) as june

sum(CASE WHEN MONTH(begin_date)= '05' THEN 1 ELSE 0 end) as june
于 2012-11-23T12:08:33.807 回答