https://github.com/natanoliveira/pivot-in-mysql
Instrução SQL PIVOT no MySQL
https://github.com/natanoliveira/pivot-in-mysql
mysql sql
Last synced: over 1 year ago
JSON representation
Instrução SQL PIVOT no MySQL
- Host: GitHub
- URL: https://github.com/natanoliveira/pivot-in-mysql
- Owner: natanoliveira
- Created: 2022-10-28T19:17:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-28T19:32:44.000Z (over 3 years ago)
- Last Synced: 2024-01-18T16:59:30.390Z (over 2 years ago)
- Topics: mysql, sql
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pivot-in-mysql
Instrução SQL "PIVOT" no MySQL
Alguns bancos de dados (por exemplo, SQL Server) têm suporte nativo para pivôs, mas o MySQL, infelizmente, não suporta a função Pivot. Um dos métodos para contornar isso e criar uma tabela dinâmica no MySQL é usar a instrução SELECT com a expressão CASE.
Para isso, você precisa criar uma instrução SELECT com a função agregada, adicionar uma instrução CASE dentro dessa função e, em seguida, adicionar uma cláusula GROUP BY.
Também é possível criar uma tabela dinâmica no MySQL usando a instrução IF dentro da função agregada.