2
My question is how to separate different values of a column into several columns and give a Count in each item according to the name in postgres, follows example below
How are you:
--TIPO O.S.--Count----Nome
     1009 ||   1   || Lucas    
     1008 ||   2   || Lucas    
     1008 ||   2   || Juliana  
     1007 ||   2   || Juliana  
     1007 ||   2   || Lucas
     1008 ||   2   || Vanessa 
     1007 ||   3   || Vanessa 
SQL: select os.tipo_os,count(os.tipo_os), pe.nome_usuario 
from table_os as os, table_pessoas as pe 
where os.codigo_usuario = pe.codpessoa
group by os.tipo_os, pe.nome_usuario
How to Stay:
--1009----1008----1007----Nome
   1   ||   2  ||   2  || Lucas    
       ||   2  ||   2  || Juliana     
       ||   2  ||   3  || Vanessa 
You want a
Pivot Table, But in postgresql you have to tell what would be the columns, it does not get it dynamically. See: http://www.vertabelo.com/blog/technical-articles/creating-pivot-tables-in-postgresql-using-the-crosstab-function– Rovann Linhalis
Even though the understanding is a little more complicated than the result presented by Bruno, it seems to me that also works Rovann, but I did not test !!
– Lucas