这个mySQL查询有什么问题?(混凝土浇筑)

这个mySQL查询有什么问题?(混凝土浇筑),mysql,Mysql,以下mySQL查询始终返回0个结果。当我添加使用concat和cast函数的部件时,问题就开始了。你能看到里面有语法错误吗 SELECT p.seccio_id as seccio, count(distinct r.usuari_upc) as usuaris, sum(r.preu) as preu FROM report r, persona p WHERE r.usuari_upc = p.persona_id and ((r.any

以下mySQL查询始终返回0个结果。当我添加使用concat和cast函数的部件时,问题就开始了。你能看到里面有语法错误吗

SELECT p.seccio_id as seccio, 
       count(distinct r.usuari_upc) as usuaris, 
       sum(r.preu) as preu
FROM report r, persona p 
WHERE r.usuari_upc = p.persona_id  
       and ((r.any = 2017 and r.mes = 1) 
            or (r.any > 2017 and r.any < 2018) 
            or (r.any = 2018 and r.mes = 1) 
            or (2017 != 2018  
                and ((r.any = 2017 and r.mes > 1)  
                or (r.any = 2018 and r.mes < 1))))  
       and (p.any_id = '2017-2018' 
           or p.any_id = '2016-2017') 
       /* The problem is here. */
       and ((r.mes < 9 
            and p.any_id = CONCAT(CAST(r.any - 1 as varchar(4)),"-",CAST(r.any as varchar(4)))) 
            or (r.mes >= 9 and p.any_id = CONCAT(CAST(r.any as varchar(4)),"-",CAST(r.any + 1 as varchar(4))))) 
GROUP BY p.seccio_id 
ORDER BY p.seccio_id

不能直接将数值转换为varchar4-如果将它们全部更改为char4,则会丢失语法错误