PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Crea una terza tabella da due tabelle

Unisci a sinistra il risultato con table2 in questo modo:

select t2."Source", to_char(coalesce(t1."The Ratio",0),'990%') "The Ratio"
from table2 t2 left outer join
  (select "Source", 100 * count(*) / sum(count(*)) over ()  "The Ratio"
   from TableA 
   group by "Source") t1
on t1."Source" = t2."Source";