我的查询有问题,所以我有两个表:工作和工作答案,所以要获得我喜欢的每项工作的答案数量:
and ((month(a.created_at) = 10 and day(a.created_at) >= 1)
or (month(a.created_at) between 11 and 12)
or (month(a.created_at) between 1 and 8)
or (month(a.created_at) = 9 and day (a.created_at) <= 30))
现在我要做的另一个修改是在每年和两个日期之间(每年 9 月 1 日和 12 月 30 日)[field : created_at] 之间获得新的工作答案数量,
+----------+-------+---------+------+----- +
| year | job title | number of answers |
+----------+-------+---------+------+------+
| 2008 | Job1 | 58 |
| 2010 | Job2 | 45 |
| 2012 | Job3 | 122 |
+----------+-------+---------+------+------
年份和日期在 created_at 字段中...
编辑 :
对于 01/10 到 30/9 我做:
and ( (month(a.created_at) = 10 and day(a.created_at) >= 1)
or month(a.created_at) between 11 and 12
or month(a.created_at) between 1 and 8
or (month(a.created_at) = 9 and day (a.created_at) <= 30))
编辑 2:
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 ;
我在声明中有语法错误?