{"id":3777,"date":"2023-03-14T12:34:04","date_gmt":"2023-03-14T05:34:04","guid":{"rendered":"https:\/\/www.bagi2info.com\/?p=3777"},"modified":"2023-09-13T17:23:08","modified_gmt":"2023-09-13T10:23:08","slug":"tabel-pivot-dinamis-mengubah-baris-menjadi-kolom","status":"publish","type":"post","link":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/","title":{"rendered":"Dynamic pivot tables (transform rows to columns)"},"content":{"rendered":"\r\n<p class=\"wp-block-paragraph\"><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A pivot table in MySQL with dynamic headers.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Assume we have a table of properties &#8211; &#8216;properties&#8217; (script for its creation is provided below), and we need to do data transformation for the report.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">+----+---------+---------------+--------+\r\n| id | item_id | property_name | value  |\r\n+----+---------+---------------+--------+\r\n|  1 |       1 | color         | blue   |\r\n|  2 |       1 | size          | large  |\r\n|  3 |       1 | weight        | 65     |\r\n|  4 |       2 | color         | orange |\r\n|  5 |       2 | weight        | 57     |\r\n|  6 |       2 | size          | large  |\r\n|  7 |       3 | size          | small  |\r\n|  8 |       3 | color         | red    |\r\n|  9 |       3 | weight        | 12     |\r\n| 10 |       4 | color         | violet |\r\n| 11 |       4 | size          | medium |\r\n| 12 |       4 | weight        | 34     |\r\n| 13 |       5 | color         | green  |\r\n| 14 |       5 | weight        | 10     |\r\n+----+---------+---------------+--------+\r\n\r\n\r\n+---------+--------+--------+--------+\r\n| item_id | color  | size   | weight |\r\n+---------+--------+--------+--------+\r\n|       1 | blue   | large  | 65     |\r\n|       2 | orange | large  | 57     |\r\n|       3 | red    | small  | 12     |\r\n|       4 | violet | medium | 34     |\r\n|       5 | green  | NULL   | 10     |\r\n+---------+--------+--------+--------+<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">There is no automatic table transformation function in MySql, as is well known (as it is). We can undoubtedly utilize a program (tool) that connects to MySql and performs data manipulation. But in this instance, we want to carry out the data rotation manually, thus we have one option: we can build a query that will do this.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">This question may be of the following types:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">SELECT\r\n  item_id,\r\n  MAX(IF(property_name = 'color', value, NULL)) AS color,\r\n  MAX(IF(property_name = 'size', value, NULL)) AS size,\r\n  ...\r\n  ...\r\n  ...\r\nFROM\r\n  properties\r\nGROUP BY\r\n  item_id;<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">As you can see, we need to take specific actions for each &#8216;property name&#8217; value. When the types of properties do not change, it can be simple. But what if the values of properties in the column &#8216;property name&#8217; frequently change or are supplemented with new ones? In this case, the query would be different each time. In this case, the dynamic query construction algorithm can assist us; this algorithm must read all possible values of the column &#8216;property name&#8217; and create a query on its foundation. The query construction algorithm is as follows:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">SET @sql = NULL;\r\nSELECT\r\n  GROUP_CONCAT(DISTINCT\r\n    CONCAT(\r\n      'MAX(IF(property_name = ''',\r\n      property_name,\r\n      ''', value, NULL)) AS ',\r\n      property_name\r\n    )\r\n  ) INTO @sql\r\nFROM properties;\r\nSET @sql = CONCAT('SELECT item_id, ', @sql, ' FROM properties GROUP BY item_id');<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">As the result will be created the query:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">SELECT\r\n  item_id,\r\n  MAX(IF(property_name = 'color', value, NULL)) AS color,\r\n  MAX(IF(property_name = 'size', value, NULL)) AS size,\r\n  MAX(IF(property_name = 'weight', value, NULL)) AS weight\r\nFROM\r\n  properties\r\nGROUP BY\r\n  item_id<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It should be noted that the GROUP CONCAT result length is restricted to the value of the system variable group concat max len, which has a default value of 1024. So, before employing the GROUP CONCAT function, this value can be made higher if you have a lot of columns, for example:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">SET @@group_concat_max_len = 5000;\r\nSELECT GROUP_CONCAT(column_name) FROM table;<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The query is written into variable @sql;&nbsp;<strong>now we can execute it with prepared statements:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">PREPARE stmt FROM @sql;\r\nEXECUTE stmt;\r\nDEALLOCATE PREPARE stmt;\r\n+---------+--------+--------+--------+\r\n| item_id | color  | size   | weight |\r\n+---------+--------+--------+--------+\r\n|       1 | blue   | large  | 65     |\r\n|       2 | orange | large  | 57     |\r\n|       3 | red    | small  | 12     |\r\n|       4 | violet | medium | 34     |\r\n|       5 | green  | NULL   | 10     |\r\n+---------+--------+--------+--------+<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Script of creation and filling of the table:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">CREATE TABLE properties (\r\n  id INT(11) NOT NULL AUTO_INCREMENT,\r\n  item_id INT(11) DEFAULT NULL,\r\n  property_name VARCHAR(255) DEFAULT NULL,\r\n  value VARCHAR(255) DEFAULT NULL,\r\n  PRIMARY KEY (id)\r\n);\r\nINSERT INTO properties VALUES \r\n  (1, 1, 'color', 'blue'),\r\n  (2, 1, 'size', 'large'),\r\n  (3, 1, 'weight', 65),\r\n  (4, 2, 'color', 'orange'),\r\n  (5, 2, 'weight', 57),\r\n  (6, 2, 'size', 'large'),\r\n  (7, 3, 'size', 'small'),\r\n  (8, 3, 'color', 'red'),\r\n  (9, 3, 'weight', 12),\r\n  (10, 4, 'color', 'violet'),\r\n  (11, 4, 'size', 'medium'),\r\n  (12, 4, 'weight', 34),\r\n  (13, 5, 'color', 'green'),\r\n  (14, 5, 'weight', 10);<\/pre>\r\n","protected":false},"excerpt":{"rendered":"<p>A pivot table in MySQL with dynamic headers. Assume we have a table of properties &#8211; &#8216;properties&#8217; (script for its creation is provided below), and we need to do data transformation for the report.&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":4193,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[246],"tags":[11,82,7],"class_list":["post-3777","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-database","tag-mysql","tag-sql"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Tabel pivot di MySQL dengan header dinamis. Asumsikan kita memiliki tabel properti - &#039;properti&#039; (skrip untuk pembuatannya disediakan di bawah), dan kita perlu melakukan transformasi data untuk laporan tersebut. +----+---------+---------------+--------+ | id | item_id | property_name | value | +----+---------+---------------+--------+ | 1 | 1 | color | blue | | 2 | 1 | size\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"webmaster\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Bagi2info.com - Tips dan Trik Komputer, Tutorial Pemrograman, SQL, PHP, React Native - Expo\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Dynamic pivot tables (transform rows to columns)\" \/>\n\t\t<meta property=\"og:description\" content=\"Tabel pivot di MySQL dengan header dinamis. Asumsikan kita memiliki tabel properti - &#039;properti&#039; (skrip untuk pembuatannya disediakan di bawah), dan kita perlu melakukan transformasi data untuk laporan tersebut. +----+---------+---------------+--------+ | id | item_id | property_name | value | +----+---------+---------------+--------+ | 1 | 1 | color | blue | | 2 | 1 | size\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/www.bagi2info.com\/wp-content\/uploads\/2017\/10\/coollogo_com-12072770.png?fit=28164&#038;ssl=1\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/i0.wp.com\/www.bagi2info.com\/wp-content\/uploads\/2017\/10\/coollogo_com-12072770.png?fit=28164&#038;ssl=1\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2023-03-14T05:34:04+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2023-09-13T10:23:08+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@bagi2infocom\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Dynamic pivot tables (transform rows to columns)\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Tabel pivot di MySQL dengan header dinamis. Asumsikan kita memiliki tabel properti - &#039;properti&#039; (skrip untuk pembuatannya disediakan di bawah), dan kita perlu melakukan transformasi data untuk laporan tersebut. +----+---------+---------------+--------+ | id | item_id | property_name | value | +----+---------+---------------+--------+ | 1 | 1 | color | blue | | 2 | 1 | size\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@bagi2infocom\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/i0.wp.com\/www.bagi2info.com\/wp-content\/uploads\/2017\/10\/coollogo_com-12072770.png?fit=28164&amp;ssl=1\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#blogposting\",\"name\":\"Dynamic pivot tables (transform rows to columns)\",\"headline\":\"Dynamic pivot tables (transform rows to columns)\",\"author\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.bagi2info.com\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/setup_learn_sql_mac.webp\",\"width\":800,\"height\":450,\"caption\":\"setup learn sql mac\"},\"datePublished\":\"2023-03-14T12:34:04+07:00\",\"dateModified\":\"2023-09-13T17:23:08+07:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#webpage\"},\"articleSection\":\"SQL, database, mysql, sql\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/category\\\/sql\\\/#listItem\",\"name\":\"SQL\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/category\\\/sql\\\/#listItem\",\"position\":2,\"name\":\"SQL\",\"item\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/category\\\/sql\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#listItem\",\"name\":\"Dynamic pivot tables (transform rows to columns)\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#listItem\",\"position\":3,\"name\":\"Dynamic pivot tables (transform rows to columns)\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/category\\\/sql\\\/#listItem\",\"name\":\"SQL\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/#person\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/38da1efad6745212e2c3b76c8d8e72f69844b6451e55a9c219cdb2bb8b8901ef?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"webmaster\"},\"sameAs\":[\"https:\\\/\\\/twitter.com\\\/bagi2infocom\",\"https:\\\/\\\/www.instagram.com\\\/bagi2infocom\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/author\\\/admin\\\/\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/38da1efad6745212e2c3b76c8d8e72f69844b6451e55a9c219cdb2bb8b8901ef?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"webmaster\"},\"sameAs\":[\"https:\\\/\\\/twitter.com\\\/bagi2infocom\",\"https:\\\/\\\/www.instagram.com\\\/bagi2infocom\"]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#webpage\",\"url\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/\",\"name\":\"Dynamic pivot tables (transform rows to columns)\",\"description\":\"Tabel pivot di MySQL dengan header dinamis. Asumsikan kita memiliki tabel properti - 'properti' (skrip untuk pembuatannya disediakan di bawah), dan kita perlu melakukan transformasi data untuk laporan tersebut. +----+---------+---------------+--------+ | id | item_id | property_name | value | +----+---------+---------------+--------+ | 1 | 1 | color | blue | | 2 | 1 | size\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/author\\\/admin\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.bagi2info.com\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/setup_learn_sql_mac.webp\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#mainImage\",\"width\":800,\"height\":450,\"caption\":\"setup learn sql mac\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/dynamic-pivot-tables-transform-rows-to-columns\\\/#mainImage\"},\"datePublished\":\"2023-03-14T12:34:04+07:00\",\"dateModified\":\"2023-09-13T17:23:08+07:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/\",\"name\":\"Bagi2info.com\",\"description\":\"Tips dan Trik Komputer, Tutorial Pemrograman, SQL, PHP, React Native - Expo\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.bagi2info.com\\\/en\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Dynamic pivot tables (transform rows to columns)","description":"Tabel pivot di MySQL dengan header dinamis. Asumsikan kita memiliki tabel properti - 'properti' (skrip untuk pembuatannya disediakan di bawah), dan kita perlu melakukan transformasi data untuk laporan tersebut. +----+---------+---------------+--------+ | id | item_id | property_name | value | +----+---------+---------------+--------+ | 1 | 1 | color | blue | | 2 | 1 | size","canonical_url":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#blogposting","name":"Dynamic pivot tables (transform rows to columns)","headline":"Dynamic pivot tables (transform rows to columns)","author":{"@id":"https:\/\/www.bagi2info.com\/en\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/www.bagi2info.com\/en\/#person"},"image":{"@type":"ImageObject","url":"https:\/\/www.bagi2info.com\/wp-content\/uploads\/2023\/03\/setup_learn_sql_mac.webp","width":800,"height":450,"caption":"setup learn sql mac"},"datePublished":"2023-03-14T12:34:04+07:00","dateModified":"2023-09-13T17:23:08+07:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#webpage"},"isPartOf":{"@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#webpage"},"articleSection":"SQL, database, mysql, sql"},{"@type":"BreadcrumbList","@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.bagi2info.com\/en\/#listItem","position":1,"name":"Home","item":"https:\/\/www.bagi2info.com\/en\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.bagi2info.com\/en\/category\/sql\/#listItem","name":"SQL"}},{"@type":"ListItem","@id":"https:\/\/www.bagi2info.com\/en\/category\/sql\/#listItem","position":2,"name":"SQL","item":"https:\/\/www.bagi2info.com\/en\/category\/sql\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#listItem","name":"Dynamic pivot tables (transform rows to columns)"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.bagi2info.com\/en\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#listItem","position":3,"name":"Dynamic pivot tables (transform rows to columns)","previousItem":{"@type":"ListItem","@id":"https:\/\/www.bagi2info.com\/en\/category\/sql\/#listItem","name":"SQL"}}]},{"@type":"Person","@id":"https:\/\/www.bagi2info.com\/en\/#person","name":"webmaster","image":{"@type":"ImageObject","@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/38da1efad6745212e2c3b76c8d8e72f69844b6451e55a9c219cdb2bb8b8901ef?s=96&d=mm&r=g","width":96,"height":96,"caption":"webmaster"},"sameAs":["https:\/\/twitter.com\/bagi2infocom","https:\/\/www.instagram.com\/bagi2infocom"]},{"@type":"Person","@id":"https:\/\/www.bagi2info.com\/en\/author\/admin\/#author","url":"https:\/\/www.bagi2info.com\/en\/author\/admin\/","name":"webmaster","image":{"@type":"ImageObject","@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/38da1efad6745212e2c3b76c8d8e72f69844b6451e55a9c219cdb2bb8b8901ef?s=96&d=mm&r=g","width":96,"height":96,"caption":"webmaster"},"sameAs":["https:\/\/twitter.com\/bagi2infocom","https:\/\/www.instagram.com\/bagi2infocom"]},{"@type":"WebPage","@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#webpage","url":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/","name":"Dynamic pivot tables (transform rows to columns)","description":"Tabel pivot di MySQL dengan header dinamis. Asumsikan kita memiliki tabel properti - 'properti' (skrip untuk pembuatannya disediakan di bawah), dan kita perlu melakukan transformasi data untuk laporan tersebut. +----+---------+---------------+--------+ | id | item_id | property_name | value | +----+---------+---------------+--------+ | 1 | 1 | color | blue | | 2 | 1 | size","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.bagi2info.com\/en\/#website"},"breadcrumb":{"@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#breadcrumblist"},"author":{"@id":"https:\/\/www.bagi2info.com\/en\/author\/admin\/#author"},"creator":{"@id":"https:\/\/www.bagi2info.com\/en\/author\/admin\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/www.bagi2info.com\/wp-content\/uploads\/2023\/03\/setup_learn_sql_mac.webp","@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#mainImage","width":800,"height":450,"caption":"setup learn sql mac"},"primaryImageOfPage":{"@id":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/#mainImage"},"datePublished":"2023-03-14T12:34:04+07:00","dateModified":"2023-09-13T17:23:08+07:00"},{"@type":"WebSite","@id":"https:\/\/www.bagi2info.com\/en\/#website","url":"https:\/\/www.bagi2info.com\/en\/","name":"Bagi2info.com","description":"Tips dan Trik Komputer, Tutorial Pemrograman, SQL, PHP, React Native - Expo","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.bagi2info.com\/en\/#person"}}]},"og:locale":"en_US","og:site_name":"Bagi2info.com - Tips dan Trik Komputer, Tutorial Pemrograman, SQL, PHP, React Native - Expo","og:type":"article","og:title":"Dynamic pivot tables (transform rows to columns)","og:description":"Tabel pivot di MySQL dengan header dinamis. Asumsikan kita memiliki tabel properti - 'properti' (skrip untuk pembuatannya disediakan di bawah), dan kita perlu melakukan transformasi data untuk laporan tersebut. +----+---------+---------------+--------+ | id | item_id | property_name | value | +----+---------+---------------+--------+ | 1 | 1 | color | blue | | 2 | 1 | size","og:url":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/","og:image":"https:\/\/i0.wp.com\/www.bagi2info.com\/wp-content\/uploads\/2017\/10\/coollogo_com-12072770.png?fit=28164&#038;ssl=1","og:image:secure_url":"https:\/\/i0.wp.com\/www.bagi2info.com\/wp-content\/uploads\/2017\/10\/coollogo_com-12072770.png?fit=28164&#038;ssl=1","article:published_time":"2023-03-14T05:34:04+00:00","article:modified_time":"2023-09-13T10:23:08+00:00","twitter:card":"summary","twitter:site":"@bagi2infocom","twitter:title":"Dynamic pivot tables (transform rows to columns)","twitter:description":"Tabel pivot di MySQL dengan header dinamis. Asumsikan kita memiliki tabel properti - 'properti' (skrip untuk pembuatannya disediakan di bawah), dan kita perlu melakukan transformasi data untuk laporan tersebut. +----+---------+---------------+--------+ | id | item_id | property_name | value | +----+---------+---------------+--------+ | 1 | 1 | color | blue | | 2 | 1 | size","twitter:creator":"@bagi2infocom","twitter:image":"https:\/\/i0.wp.com\/www.bagi2info.com\/wp-content\/uploads\/2017\/10\/coollogo_com-12072770.png?fit=28164&ssl=1"},"aioseo_meta_data":{"post_id":"3777","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2023-01-11 04:58:08","updated":"2025-06-04 08:41:44","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.bagi2info.com\/en\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.bagi2info.com\/en\/category\/sql\/\" title=\"SQL\">SQL<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tDynamic pivot tables (transform rows to columns)\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.bagi2info.com\/en\/"},{"label":"SQL","link":"https:\/\/www.bagi2info.com\/en\/category\/sql\/"},{"label":"Dynamic pivot tables (transform rows to columns)","link":"https:\/\/www.bagi2info.com\/en\/dynamic-pivot-tables-transform-rows-to-columns\/"}],"_links":{"self":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts\/3777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/comments?post=3777"}],"version-history":[{"count":10,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts\/3777\/revisions"}],"predecessor-version":[{"id":4190,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts\/3777\/revisions\/4190"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/media\/4193"}],"wp:attachment":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/media?parent=3777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/categories?post=3777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/tags?post=3777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}