Forum Moderators: open
is there anything about this query which would be interperted differently by two different database servers?
here's the query:
select c.id, c.fname, c.lname,
(select count(distinct p.id) from gteams.points p
join team_map tm on tm.celebrity_id = p.celebrity_id
where p.date > date_add(l.begin_date, INTERVAL 0 DAY)
and p.date < date_add(l.begin_date, INTERVAL 7 DAY)
and p.celebrity_id = c.id and tm.team_id=t.id
and
case when tm.date_removed is null
then p.date > tm.date_added
else (p.date > tm.date_added AND p.date < tm.date_removed)
end) as week_1_points,
(select count(distinct p.id) from gteams.points p
join team_map tm on tm.celebrity_id = p.celebrity_id
where p.date > date_add(l.begin_date, INTERVAL 7 DAY)
and p.date < date_add(l.begin_date, INTERVAL 14 DAY)
and p.celebrity_id = c.id
and tm.team_id=t.id and
case when tm.date_removed is null
then p.date > tm.date_added
else (p.date > tm.date_added AND p.date < tm.date_removed)
end) as week_2_points
from gteams.team t
join gteams.team_map tm on tm.team_id = t.id
join gteams.celebrity c on c.id = tm.celebrity_id
left join gteams.points p on p.celebrity_id = c.id
join gteams.league l on l.id = t.league_id
where t.id = 27
group by c.id