-WITH hostile_alliances AS (
- SELECT COALESCE(aid,-1) AS aid, count(*) AS hostile_count
+WITH hostile_fleets AS (
+ SELECT DISTINCT s.pid, COALESCE(s.aid,-1) AS aid, i.target, i.tick
+ FROM intel i
+ JOIN current_planet_stats s ON s.pid = i.sender
+ JOIN current_planet_stats t ON t.pid = i.target
+ WHERE t.alliance = 'NewDawn' AND i.mission = 'Attack' AND i.tick BETWEEN $1 AND $2
+ UNION DISTINCT
+ SELECT s.pid, COALESCE(s.aid,-1) AS aid, u.pid AS target, c.landing_tick