Skip to content

Instantly share code, notes, and snippets.

@marcellobenigno
Created July 14, 2013 20:59
Show Gist options
  • Save marcellobenigno/5996003 to your computer and use it in GitHub Desktop.
Save marcellobenigno/5996003 to your computer and use it in GitHub Desktop.
Exemplo de Pivot Table
SELECT bairro,
sum(CASE WHEN sexo ='MASCULINO' THEN 1 ELSE 0 END) AS total_homens,
sum(CASE WHEN sexo ='FEMININO' THEN 1 ELSE 0 END) AS total_mulheres
FROM acidentes
GROUP BY bairro
ORDER BY total_homens DESC, total_mulheres DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment