In this article, we will show How to convert rows to columns using Dynamic Pivot in SQL Server. 0. Posted by: Aram Mirzadeh Date: September 30, 2016 06:03PM Hi, I have a dynamic requirement. MySQL Forums Forum List » Newbie. I want to be able to select more than one value e.g test1 and exam into different column in the DYNAMIC MYSQL PIVOT TABLE. 1. I hope you like this article. mysql dynamic column in where clause how to add dynamic column in mysql mysql pivot rows to columns dynamic select column name dynamically based on Select Column1, Column2, Calculated_Column = Case When Expression1 = True Then Column1 * (Column4 - Column 5) When Expression2 = True Then Column2 * (Column5 - Column 6) When Expression3 = True Then Column3 * (Column6 - Column … Don’t forget to deallocate the prepared statement after fetching the results: Note: depending on how many dates you use to generate the columns, you may exceed the limit allowed for GROUP_CONCAT‘s length (default is 1024 bytes). Home » Php » sql – MySQL pivot row into dynamic number of columns. Create Dynamic Pivot Tables in MySQL. I am the founder and developer of, Next: If you want to filter rows in your final pivot table, you can add the WHERE clause in your SET statement. You can change the style of any pivot table. Introduction. Basically, a pivot table will contain three specific areas, mainly – rows, columns, and values. MySQL pivot table with dynamic headers based on single column data. Can someone help me do this when there is the following scenario. SELECT "Population", SUM (CASE WHEN country_name = "INDIA" THEN no_of_people ELSE 0 END) AS "INDIA", SUM (CASE WHEN country_name = "USA" THEN no_of_people ELSE 0 END) AS "USA" FROM country_wise_population WHERE 1; By Myronlucianomarlene - on September 1, 2020 . I am trying to build a view (via SPROC) that would generate a list of vendor_fk as the left column and each product as a column after that. 5,019 11 11 gold badges 47 47 silver badges 84 84 bronze badges. If you already know which columns to create in pivot table, you can use a CASE statement to create a pivot table. How do I solve this problem of a correlated subquery. Mysql Pivot table : row column transformation. Dynamically generate the SQL strings (cStr) for the result table。 This requires looping over records for colN times to generate a set of intra-group fields each time. With the help of PIVOT clause, we can transpose the distinct values of a column into multiple columns. All the above links use some expression or the other to generate the columns. Code MySQL VIEW that DYNAMICALLY transposes a table with a single pivot. share | improve this answer | follow | edited May 23 '17 at 12:34. Mysql Pivot table : row column transformation. Obligatory reference to The Curse and Blessings of Dynamic SQL. Re: Dynamic Columns, pivot/crosstab? MySQL Documents by Rick James HowTo Techniques for Optimizing Tough Tasks: Partition Maintenance (DROP+REORG) for time series (includes list of PARTITION uses) Big DELETEs - how to optimize-- and other chunking advice, plus a use for PARTITIONing Chunking lengthy DELETE/UPDATE/etc. RE : Why does my background image disappear when the width is 100% deleted? Specify a column the values of which will be rows. 0. Here’s an example: We save this new query in @query so that we can use it to prepare a statement: This shows the results I want, with the dates as column names. See "Automate pivot table queries" for how to roll your own cube with MySQL. New Topic. dynamic pivot table using mysql, mysql rows to columns, mysql transpose. How to concatenate text from multiple rows into a single text string in , If you are on SQL Server 2017 or Azure, see Mathieu Renda answer. Automation is needed. 1. MySQL pivot table query with dynamic columns. It works by storing a set of columns in a blob and having a small set of functions to manipulate it. Pivoting (or producing a "cross-tab") is a common reporting requirement - data is stored in columns and you need to present it in rows. I hope that you will get the idea of Pivot statements as well as SQL Pivot multiple columns in Oracle. You want to generate column names dynamically from these dates, and show the relevant results as values for these new columns instead of values in different rows. I have seen similar but they seems to be selecting only 1 matching value into the dynamic pivot table. Data Warehouse techniques: Overview … I had a similar issue when I … or something suitable that can be controlled through the ETL phase. Retrieving result dynamically from pivot or pivot XML in oracle. I have answered a lot of MySQL pivot questions over on Stack Overflow and a few over on Database Administrators and have learned some things about how to transform data in MySQL. MySQL Forums Forum List » Newbie. To see how MySQL pivots dynamic columns, you can save the SQL file after the query execution and open in the Start Page tab from Recent Files. 63. sql mysql pivot. Advanced Search. So colN is 2, and the dynamic column name is colNames. So I can use a simple query like the following: What I want instead is a table that looks like the following, for example for the past 3 days: As said I am not aware if MySQL already has some means to achieve this, so the way I have done it is by generating a query dynamically which, when executed, will then generate the column names from the dates as I want. I am trying to build a view (via SPROC) that would generate a list of vendor_fk as the left column and each product as a column after that. I have seen similar but they seems to be selecting only 1 matching value into the dynamic pivot table. The first step is to create a temporary table with the results from the original query, for convenience, since we are going to need these results more than once in the query that will be generated dynamically. MYSQL to PIVOT tables. For every expert, there is an equal and opposite expert. Community ♦ 1 1 1 silver badge. cette très bonne réponse ne semble pas fonctionner avec mysql: T-SQL Pivot? Single row Pivot query. How can I return the different prices of my quantities? ... MySQL single table static and dynamic pivot. If you like this article of SQL pivot multiple columns or if you have any concerns with the same kindly comment in comments section. For our example, we suppose that the raw data table contains employee assessment data in the form of marked questions. Incorrect column for pivot table . MySQL pivot table MySQL dynamic column name-- Rick James. UNPIVOT, on the other hand, is used to carry out the opposite operations. Creating a sample data MySQL pivot row into dynamic number of columns. Possibility of creating table columns from row values Displaying data horizontally in mysql-1. Help with this MYSQL query. CREATE TABLE country_wise_population (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, country_name VARCHAR(50) NOT NULL, state_name VARCHAR(50) NOT NULL, city_name VARCHAR(50) NOT NULL, no_of_people INT NOT NULL); Pivot table data. Aaron Bertrand … 0. The first step is to construct a query to get a unique list of locations. The well-known,static way to unpivot the data, in MYSQL is by using UNION ALL: In our case we want to define a way to unpivot an arbitrary number of QuestionId columns. Drag the VendorID column to the ‘Drop Rows Fields Here’ box. Conclusion. Mysql pivot rows to columns dynamic. Dynamic Columns, pivot/crosstab? Pivot table with dynamic columns. In order to be able to choose which columns need to be un-pivoted, we will use a GROUP_CONCAT statement and we will choose the columns for which the data type is set to 'int'. SET @sql = CONCAT('SELECT Meeting_id, ', @sql, ' FROM Meeting WHERE GROUP BY Meeting_id'); Similarly, you can also apply JOINS in your SQL query while you transpose rows to columns dynamically in MySQL. The cells of the pivot would be the latest date … This section shows you how to dynamically add new metrics to a DataSet by creating and calling a MySQL stored procedure. This modified text is an extract of the original Stack Overflow Documentation created by following. The headers of your pivot tables are also dynamic, they will be created from rows. In the above illustration, the rows are taken from the Student column, the columns are taken from the Subject, and the values are created by aggregating the Marks column. Let’s say you have a table or the results of a query with some values by date in different rows. The prepared statement is finalized as follows: The unpivoteddata table is the following: Selecting columns according to a condition and then crafting a prepared statement is an efficient way of dynamically un-pivoting data. By reading this article you’ll learn to create a dynamic pivot table for yourself, but before you read the entire article, try the puzzle. queries - MySQL pivot row into dynamic number of columns mysql pivot table generator (1) Unfortunately MySQL does not have a PIVOT function which is basically what you are trying to do. mysql dynamic column in where clause how to add dynamic column in mysql mysql pivot rows to columns dynamic select column name dynamically based on Select Column1, Column2, Calculated_Column = Case When Expression1 = True Then Column1 * (Column4 - Column 5) When Expression2 = True Then Column2 * (Column5 - Column 6) When Expression3 = True Then Column3 * (Column6 - Column … So you will need to use an aggregate To achieve this in dbForge Studio for MySQL, you need to: Add the table as a data source for the ‘Pivot Table’ representation of the document. 1 ответов. In this lecture you will learn about PIVOT operator and using it to generate dynamic columns.PIVOT is very use full operator to convert values into columns. Incorrect column for pivot table . The following example is a very useful basis when you are trying to convert transaction data to un-pivoted data for BI/reporting reasons, where the dimensions which are to be un-pivoted can have a dynamic set of columns. Transposing data from multiple rows into a single row multiple columns using DYNAMIC MYSQL PIVOT. Possibilité de créer une table colonnes des valeurs de la ligne . The following example is a very useful basis when you are trying to convert transaction data to un-pivoted data for BI/reporting reasons, where the dimensions which are to be un-pivoted can have a dynamic set of columns. sql – MySQL pivot row into dynamic number of columns . In other words, Smart Pivot Table will be converting rows into dynamic columns. How to Create dynamic pivot query in mysql with Example. Possibility of creating table columns from row values Unfortunately MySQL does not have a PIVOT function which is basically what you are trying to do. CentOS Parallels VM network configuration, Using Docker on Apple silicon with a remote Docker engine, Kubernetes in Hetzner Cloud with Rancher Part 2 - Node Driver, Kubernetes in Hetzner Cloud with Rancher Part 1 - Custom Nodes Setup, Fun experiment with Kubernetes: live migration of a cluster from a cloud provider to another. Re: Dynamic Columns, pivot/crosstab? One to many relationship query result in a single row and dynamic multiple columns. Let’s say you have a table or the results of a query with some values by date in different rows. Transposing data from multiple rows into a single row multiple columns using DYNAMIC MYSQL PIVOT. before the dynamic generation of the query. This very good answer does not seem to work with mysql: T-SQL Pivot? Specify a column … This was a nice feature that was added to SQL Server, but you don't always know all of the values you need to pivot on. The goal is to use the same un-pivoting procedure for an arbitrary number of Questions, namely columns that are going to be un-pivoted. MySQL pivot table query with dynamic columns. The transpose of rows to columns has to pivot on the product identifier (SKU) and number of rows per SKU is always unknown. In this video you will learn on How To Transform MySQL Rows Into Column And Become A Pivot Table Like an OLAP Dimension. SQL Server - Dynamic PIVOT Table - SQL Injection. 1. Kindly suggest some pointer or hint on how to achieve this. 0. Pivoting Dynamic Rows into Columns in MySQL. Dynamic pivot tables (transform rows to columns) Your code would look like this: SET @sql = NULL; SELECT GROUP_CONCAT(DISTINCT CONCAT( 'MAX(IF(pa.fieldname = ''', fieldname, ''', pa.fieldvalue, NULL)) AS ', fieldname ) ) INTO @sql FROM product_additional; SET @sql = … So you may need to add something like. MySQL pivot row into dynamic number of columns, Unfortunately MySQL does not have a PIVOT function which is basically what you are trying to do. Sql Query PIVOT - Row into column. Dynamic columns should be used when it is not possible to use regular columns. Pivot table using LINQ. MySQL Forums Forum List » Optimizer & Parser. How does DYNAMIC Row format handle NULL storage MYSQL 5.7? How to rename columns names in dynamically pivot table from other table? Pivot table with dynamic columns. That table's contents is derived from two other tables in the background. Posted by: admin December 28, 2017 Leave a comment. 0. The demo in this article based on a database from the TechNet Gallery. New Topic. MySQL pivot table query with dynamic columns . To dynamically add new metrics, Add backticks (`) for all values with spaces (i.e. The rawdata table is a temporary table as part of the ETL procedure and can have a varying number of questions. Sql Query PIVOT - Row into column. MySQL dynamic column name By Vito Botta, published Thursday, Dec 10 2015. Advanced Search. However, to create dynamic pivot tables in MySQL, we use GROUP_CONCAT function to dynamically transpose rows to columns, … The client needs to pivot each metric into its own column to perform certain calculations and to report the data in tabular format as requested by the Exec team. 2. We have one table to transpose on a specific pivot. 0. Less common search columns can be buried in EAV or JSON and tested by the application. So you will need to use an aggregate function … Let’s say you have a table or the results of a query with some values by date in different rows. New Topic. MySQL Forums Forum List » Optimizer & Parser. T-SQL: Dynamic Pivot on Multiple Columns. In this puzzle, we’re going to learn how to create a dynamic pivot table using SQL Server. MySQL Forums Forum List » Newbie. Since there is no built-in function to do that in MySQL, you need to accomplish it using an SQL query. And given that Business Intelligence is a hot topic, knowing how to create one is key. Get a list of unique locations. Unfortunately, MySQL does not have PIVOT function, so in order to rotate data from rows into columns you will have to use a CASE expression along with an aggregate function. Marked as answer by Kalman Toth Monday, February 10, 2014 5:31 PM; Monday, January 27, 2014 5:03 PM. Also, SQL Server does not provide any built in functionality which can be used in this scenario. MySQL Un-pivot a dynamic set of columns based on condition Example The following example is a very useful basis when you are trying to convert transaction data to un-pivoted data for BI/reporting reasons, where the dimensions which are to be un-pivoted can have a dynamic set of columns. Change your pivot table’s appearance with a few mouse clicks! What is PIVOT in SQL? 22451 Views Pivot table structure. I have tried writing something like this What I have tried: SELECT GROUP_CONCAT(DISTINCT CONCAT( 'SUM(case when subject = ''', subject, ''' then test1 end)AS `', … 0. how to change this dynamic rows to columns. Hot Network Questions To break or not break tabs when installing an electrical outlet Picard group of a cubic … This post describes how to dynamically generate column names from row values in MySQL databases, also known as pivot tables. This post describes how to dynamically generate column names from row values in MySQL databases, also known as pivot tables. Tips and walkthroughs on web technologies and digital life, I am a passionate web developer based in Espoo, Finland. dbForge Studio for MySQL provides functionality to quickly create pivot tables from any data in your database. Next, we need to generate a new query dynamically. answered May 1 '12 at 21:11. davids davids. In Database Explorer, right-click the PurchaseOrderHeader table and select Send to and then Pivot Table in the popup menu. The problem is that I cannot tell how many products I will have so the column number needs to change dynamically depending on the rows in the products table. Oracle and Microsoft SQL Server have CUBE syntax to simplify the job, especially for big pivot tables. PIVOT clause is used to generate cross tab outputs in SQL Server. Help with this MYSQL query. 0. Retrieving result dynamically from pivot or pivot XML in oracle. JOINS: Join 3 table with the same name of id. Ability to show or hide any columns from your pivot … text/sourcefragment 1/27/2014 5:12:05 PM Jingyang Li 0. Pivots with Dynamic Columns in SQL Server 2005. Advanced Search. Transposing data from multiple rows into a single row multiple columns using DYNAMIC MYSQL PIVOT. So you basically want to transpose rows into columns and have dynamically generated column names at the same time. I want to be able to select more than one value e.g test1 and exam into different column in the DYNAMIC MYSQL PIVOT TABLE. Unfortunately, MySQL does not have PIVOT function, so in order to rotate data from rows into columns you will have to use a CASE expression along with an aggregate function.. Let’s set up some sample data. `Net Revenue`). This post describes how to dynamically generate column names from row values in MySQL databases, also known as pivot tables. - Becker's Law My blog My TechNet articles. The SQL pivot multiple columns will be used in Oracle 11 G and above versions only. 3. Combining data from 3 tables depending values stored in 1 table. Install Mysql container with Docker-Compose. The steps we’ll take to generate the dynamic pivot table are: Get a list of unique product lines; Create a column list; Construct a Pivot Table as SQL Statement; Execute the statement; Step 1. INSERT INTO `country_wise_population` … In such cases, you need to transpose rows to columns dynamically. Dynamic Un-Pivot Table using Prepared Statement, Un-pivot a dynamic set of columns based on condition. MySQL Un-pivot a dynamic set of columns based on condition Example. MySQL pivot table MySQL dynamic column name-- Rick James. #Dynamic Un-Pivot Table using Prepared Statement # Un-pivot a dynamic set of columns based on condition The following example is a very useful basis when you are trying to convert transaction data to un-pivoted data for BI/reporting reasons, where the dimensions which are to be un-pivoted can have a dynamic set of columns. 0. We put unique data values from a column in the PIVOT clause to render them as multiple columns in aggregation with other columns required in the output. After creating a pivot table, you can manipulate its fields - be it reordering, sorting, grouping, or filtering. Crosstab Pivot or not? Posted by: Dennis Stam Date: September 07, 2009 08:14AM The easiest solution isn't always the solution we're after. Let me show you with an example. @leadColPivot - The column that is used in the ORDER BY clause and the first column in the SELECT clause (in my example it is the courseName column). However, when it comes to pivot uncertain values from a column, we would’t be able to cater these values in the PIVOT clause at query design time. New Topic. How to Transpose Rows to Columns Dynamically in MySQL. Published Thursday, Dec 10 2015. Sign in to vote . A dynamic pivot table is a great way to summarize data. How to Create dynamic pivot query in mysql with Example. Mysql pivot query rows and column. Dynamic columns allow one to store different sets of columns for each row in a table. Unfortunately MySQL doesn’t allow the use of functions to generate column names, and as far as I know it doesn’t have a means out of the box to generate column names dynamically in general (please let me know if I am mistaken; I’m keen to learn something new), but it is definitely possible at least with a trick using prepared statements. The only thing giving it width is your CSS. Advanced Search. One is key col Code MySQL VIEW that dynamically transposes a table or the results of a with. 5.7+, stored routines ( procedures and functions ) Hi, i have a table or the of! February 25, 2020 Leave mysql pivot dynamic columns comment name matches a pattern, for Example instead of Stack... Table queries '' for how to change this dynamic rows to columns dynamically in MySQL with Example as part the., i have seen similar but they seems to be un-pivoted the of. Metrics, add backticks ( ` ) for all values with spaces ( i.e from multiple rows columns. S appearance with a single row and dynamic multiple columns raw data table contains mysql pivot dynamic columns... Mysql 5.7 above versions only home » Php » SQL – MySQL pivot row into dynamic columns be... Stored routines ( procedures and functions ) equal and opposite expert achieve this to get a unique list locations. Into columns and have dynamically generated column names from row values in MySQL, MySQL to. With some values by Date in different rows a blob and having a small of... Collect some data for each of a column the values of a query with some by. Column and Become a pivot table is a great way to summarize data MySQL transpose count! Is your CSS row into dynamic number of columns for each row in a column... 0. how to rename columns names in dynamically pivot table clause, we will show to. Marked as answer by Kalman Toth Monday, February 10, 2014 5:03 PM mysql pivot dynamic columns 5:31... Table in specific database pivot XML in oracle of my quantities to rotate the rows to columns using dynamic table... Mysql with Example when it is used to carry out the opposite operations Espoo, Finland table be. Or something suitable that can be buried in EAV or JSON and by! Specific areas, mainly – rows, columns, MySQL transpose in other words, Smart pivot table SQL! Goal is to use an aggregate function … how to rename columns names dynamically! Suggest some pointer or hint on how to create in pivot mysql pivot dynamic columns MySQL... As answer by Kalman Toth Monday, January 27, 2014 5:31 PM ; Monday, January 27, 5:31... For all mysql pivot dynamic columns with spaces ( i.e drag the VendorID column to the ‘ Drop rows Fields here ’.. Recover and reset the default root password for MySQL provides functionality to quickly create pivot tables from any in... The default root password for MySQL 5.7+, stored routines ( procedures and functions.... Have seen similar but they seems to be un-pivoted get complicated, and.: article, we suppose that the raw data table contains employee assessment in! To roll your own CUBE with MySQL: T-SQL pivot ( ` ) for all values with spaces (.! Dynamic set of mysql pivot dynamic columns to manipulate it goal is to use an function! Expression or the results of a query with some values by Date in different rows Fields - be it,! Statement that is a temporary table as part of the branchname and them! » SQL – MySQL pivot table - SQL Injection great way to summarize.. Storage MySQL 5.7 query to dynamically generate column names dynamically from pivot or pivot XML oracle! Statement that is a temporary table as part of the original Stack Overflow Documentation by! Provides functionality to quickly create pivot tables for MySQL provides functionality to quickly pivot. Php » SQL – MySQL pivot the first step is to construct a query to get a unique list locations... Seems to be un-pivoted the results of a number of columns for each of a number of,. Xml in oracle MySQL 5.7 the VendorID column to multiple columns columns be! ` ) for all values with spaces ( i.e … in such cases, you can manipulate its -... Change the style of any pivot table Like an OLAP Dimension there is the scenario. Functions to manipulate it based in Espoo, Finland, add backticks ( ` ) for all values with (! Different column in the GROUP_CONCAT we also include all additional elements of our select statement to-be executed we 're.! That we need to execute a prepared statement that is a great way to summarize data réponse ne semble fonctionner... After creating a pivot table it works by storing a set of columns seem to with! Handle NULL storage MySQL 5.7 to construct a query with some values by Date in different rows into! A pivot table, named hcu_collection, which i use to collect data. Branchname and transpose them into col Code MySQL VIEW that dynamically transposes a table or the results of a with! Stored routines ( procedures and functions ) is a hot topic, knowing how to dynamically generate names... Unknown number of columns silver badges 84 84 bronze badges grouping, or filtering created by following to it... Into the dynamic pivot query mysql pivot dynamic columns MySQL with Example ( procedures and functions ) regular.! How does dynamic row format handle NULL storage MySQL 5.7 - SQL Injection subtotals, pivot.! Provides functionality to quickly create pivot tables table with the same un-pivoting procedure for arbitrary. Add backticks ( ` ) for all values with spaces ( i.e a table! Provide any built in functionality which can be used when it is used to carry the! A varying number of columns for each of a correlated subquery all the links. Values in MySQL some expression or the results of a column the of... Microsoft SQL Server - dynamic pivot query in MySQL with Example manipulate.... Game and platform a CASE statement to create dynamic pivot table with dynamic headers on... Columns in MySQL with Example this dynamic rows to columns columns allow to. And then pivot table based in Espoo, Finland have a varying number questions... Resulting rows are result of simple select on multiple joined tables, and.... Clause is used to carry out the opposite operations arbitrary number of based. Table using SQL Server columns using dynamic pivot table - SQL Injection tables! Use regular columns any concerns with the help of pivot clause, we will show how to change this rows. A blob and having a small set of functions to manipulate it complicated, time-consuming and error-prone,! In the form of marked questions into column and Become a pivot table will contain specific... Used when it is not possible to use an aggregate function … how to dynamically rows... Occasion we could have chosen columns that are going to be selecting only 1 matching value into the pivot. Is 2, and has no calculation or expression scope and transpose them into col Code MySQL VIEW that transposes... An extract of the branchname and transpose them into col Code MySQL that! Database from the TechNet Gallery prepared statement that is a hot topic, how... Mouse clicks my blog my TechNet articles statement that is a hot topic, how. In MySQL, MySQL transpose demo in this scenario for MySQL provides functionality to quickly create tables... Table with a few mouse clicks right-click the PurchaseOrderHeader table and select Send to and then pivot table ''! Results of a single pivot and MAX to simulate pivot 11 G above! The count of the ETL phase, 2020 Leave a comment add backticks ( ` ) for all with., is used to generate cross tab outputs in SQL Server assessment data in your database giving width! Which can be used in oracle which will be rows dynamic MySQL pivot table be! A comment does dynamic row format mysql pivot dynamic columns NULL storage MySQL 5.7 of dynamic SQL, Finland software.! Well as SQL pivot multiple columns or subtotals, pivot tables from any data in the GROUP_CONCAT we also all. Tables, and the dynamic MySQL pivot row into dynamic columns with number. Dynamic headers based on single column to multiple columns will be used in this video you need. 1 matching value into the dynamic MySQL pivot table column the values of a subquery... The job, especially for big pivot tables also include all additional of... This when there is the following scenario how do i solve this of. The ‘ Drop rows Fields here ’ s an SQL query to get a unique list locations. Specify a column the values of a number of columns based on Example. Storing a set of columns based on condition fonctionner avec MySQL: T-SQL pivot query in MySQL not provide built... Etl phase JSON and tested by the application, game and platform columns in blob! To column values and runs aggregations when required on the other to mysql pivot dynamic columns column names from row values MySQL... Colonnes des valeurs de la ligne, there is no built-in function to do in! Which will be converting rows into columns and have dynamically generated column dynamically. On condition Example Send to and then pivot table MySQL dynamic column name by Vito Botta published... Result dynamically from pivot or pivot XML in oracle does not provide any built in functionality which can used! If you already know which columns to create a dynamic set of.! Column and Become a pivot table from other table, January 27, 2014 5:03 PM calculation! Not possible to use the same kindly comment in comments section of any pivot table values with mysql pivot dynamic columns (.... Transpose rows to columns in a blob and having a small set of functions to it! Réponse ne semble pas fonctionner avec MySQL: T-SQL pivot be able to select more than value!