「declare」を使用すると構文エラーが発生します:
delimiter $$
begin
declare @StartDay INT, @EndDay INT, @StartMonth INT, @EndMonth INT
Select @StartDay = 01, @StartMonth = 10, @EndDay = 30, @EndMonth = 09
Select year(a.created_at) as years , jd.JobDomain, count(a.Id) as nb_answer, a.Job_id, j.JobTitle
from JobAppliance a
inner join Job j on a.Job_id = j.PublicId
inner join JobDestination d on j.Id=d.Job_id
inner join Jjobdomain jd on j.Id = jd.Job_id
and
(
@StartMonth = @EndMonth And
Month(a.created_at) = @StartMonth And
Day(a.created_at) >= @StartDay And
Day(a.created_at) <= @EndDay
) Or (
@StartMonth != @EndMonth And (
(
Month(a.created_at) = @StartMonth And
Day(a.created_at) >= @StartDay
) Or (
Month(a.created_at) Between @StartMonth + 1 And @EndMonth - 1
) Or (
Month(a.created_at) = @EndMonth And
Day(a.created_at) <= @EndDay
)
)
)
group by year(a.created_at) , a.Job_id, j.JobTitle;
end$$
delimiter ;
Mysqlワークベンチを使用しています
編集 :
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
'@StartDay int, @EndDay int, @StartMonth int,
@EndMonth intSelect @StartDay = 0' at line 3