I have a problem with query so I have two tables : Job and Job answers,so to get number of answers of every job I do like that :
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))
Now I have another modification to do is to get a new number of answers of job by per year and between two date ( 1 september and 30 december for every year) [field : created_at] ,
+----------+-------+---------+------+----- +
| year | job title | number of answers |
+----------+-------+---------+------+------+
| 2008 | Job1 | 58 |
| 2010 | Job2 | 45 |
| 2012 | Job3 | 122 |
+----------+-------+---------+------+------
year and date is in created_at field…
Edit :
for 01/10 to 30/9 I do :
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))
edit 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 ;
I have a syntax error in declare?
This should give what you want:
Updated to newly specified date range
A more general solution would be to have a table with start_date, end_date for defining the ranges of interest and joining to that instead.
This might work more generally for a continuous date range within a year, but I haven’t tested it. The idea is that you fill out the values of @StartDay etc that you want