]> ruin.nu Git - ndwebbie.git/blob - database/views/defcalls.sql
Clean up database directory
[ndwebbie.git] / database / views / defcalls.sql
1 CREATE OR REPLACE VIEW defcalls AS
2 SELECT call, status,c.uid, c.landing_tick
3         ,dc.username AS dc, (c.landing_tick - tick()) AS curreta
4         ,array_agg(COALESCE(race::text,'')) AS race
5         ,array_agg(COALESCE(amount,0)) AS amount
6         ,array_agg(COALESCE(eta,0)) AS eta
7         ,array_agg(COALESCE(shiptype,'')) AS shiptype
8         ,array_agg(COALESCE(alliance,'?')) AS alliance
9         ,array_agg(coords(p2.x,p2.y,p2.z)) AS attackers
10 FROM calls c
11         LEFT OUTER JOIN incomings i USING (call)
12         LEFT OUTER JOIN current_planet_stats p2 USING (pid)
13         LEFT OUTER JOIN users dc ON c.dc = dc.uid
14 GROUP BY call,c.uid,dc.username, c.landing_tick, status;
15
16 CREATE OR REPLACE VIEW full_defcalls AS
17 SELECT call,status,x,y,z,pid,landing_tick,dc,curreta
18         ,defprio, c.race, amount, c.eta, shiptype, c.alliance, attackers
19         ,COUNT(NULLIF(f.back = f.landing_tick + f.eta - 1, FALSE)) AS fleets
20 FROM users_defprio u
21         JOIN current_planet_stats p USING (pid)
22         JOIN defcalls c USING (uid)
23         LEFT OUTER JOIN launch_confirmations f USING (pid,landing_tick)
24 GROUP BY call, x,y,z,pid,landing_tick,dc,curreta,defprio,c.race,amount,c.eta,shiptype,c.alliance,attackers, status
25 ;