{"id":3039,"date":"2024-06-07T11:52:09","date_gmt":"2024-06-07T03:52:09","guid":{"rendered":"https:\/\/five.co\/?p=3039"},"modified":"2026-05-04T15:21:56","modified_gmt":"2026-05-04T07:21:56","slug":"pivot-tables-sql","status":"publish","type":"post","link":"https:\/\/preview-php85.dzine.org\/five\/blog\/pivot-tables-sql\/","title":{"rendered":"How to Pivot Tables in SQL"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Pivoting tables in SQL is a common task for programmers, database administrators (DBAs), data analysts or anyone else querying SQL databases. <strong>In SQL, a pivot is used to transform (or pivot) rows of data into columns<\/strong> to generate insights from our data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s learn how to pivot a table in SQL. We will illustrate how to perform an SQL pivot with an easy-to-understand example. <\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<div class=\"root-eb-toc-rxxjy wp-block-essential-blocks-table-of-contents\"><div class=\"eb-parent-wrapper eb-parent-eb-toc-rxxjy \"><div class=\"eb-toc-container eb-toc-rxxjy  eb-toc-is-not-sticky eb-toc-not-collapsible eb-toc-initially-not-collapsed eb-toc-scrollToTop style-1 list-style-none\" data-scroll-top=\"false\" data-scroll-top-icon=\"fas fa-angle-up\" data-collapsible=\"false\" data-sticky-hide-mobile=\"false\" data-sticky=\"false\" data-scroll-target=\"scroll_to_toc\" data-copy-link=\"false\" data-editor-type=\"\" data-hide-desktop=\"false\" data-hide-tab=\"false\" data-hide-mobile=\"false\" data-itemcollapsed=\"false\" data-highlight-scroll=\"false\"><div class=\"eb-toc-header\"><h2 class=\"eb-toc-title\">Table of Contents<\/h2><\/div><div class=\"eb-toc-wrapper \" data-headers=\"[{&quot;level&quot;:3,&quot;content&quot;:&quot;Why Do We Need to Pivot Tables in SQL?&quot;,&quot;text&quot;:&quot;Why Do We Need to Pivot Tables in SQL?&quot;,&quot;link&quot;:&quot;why-do-we-need-to-pivot-tables-in-sql&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Pivot Tables in SQL&quot;,&quot;text&quot;:&quot;Pivot Tables in SQL&quot;,&quot;link&quot;:&quot;pivot-tables-in-sql&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Creating a Web Front End For a SQL Database&quot;,&quot;text&quot;:&quot;Creating a Web Front End For a SQL Database&quot;,&quot;link&quot;:&quot;creating-a-web-front-end-for-a-sql-database&quot;}]\" data-visible=\"[true,true,true,true,true,true]\" data-delete-headers=\"[{&quot;label&quot;:&quot;Why Do We Need to Pivot Tables in SQL?&quot;,&quot;value&quot;:&quot;why-do-we-need-to-pivot-tables-in-sql&quot;,&quot;isDelete&quot;:true},{&quot;label&quot;:&quot;Pivot Tables in SQL&quot;,&quot;value&quot;:&quot;pivot-tables-in-sql&quot;,&quot;isDelete&quot;:true},{&quot;label&quot;:&quot;Creating a Web Front End For a SQL Database&quot;,&quot;value&quot;:&quot;creating-a-web-front-end-for-a-sql-database&quot;,&quot;isDelete&quot;:true}]\" data-smooth=\"true\" data-top-offset=\"\"><div class=\"eb-toc__list-wrap\"><ul class=\"eb-toc__list\"><li><a href=\"#why-do-we-need-to-pivot-tables-in-sql\">Why Do We Need to Pivot Tables in SQL?<\/a><li><a href=\"#pivot-tables-in-sql\">Pivot Tables in SQL<\/a><li><a href=\"#creating-a-web-front-end-for-a-sql-database\">Creating a Web Front End For a SQL Database<\/a><\/ul><\/div><\/div><\/div><\/div><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Why Do We Need to Pivot Tables in SQL?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SQL databases store data in columns and rows. Columns are referred to as fields, and rows as records. Oftentimes, we want to change the way our data is presented to us or our stakeholders. Pivot tables are a tool used for summarizing data and generating insights from it. They are a critical feature in reporting, business intelligence or analysis and let us present data in a more readable, quicker-to-understand format.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img width=\"1024\" height=\"1024\" src=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivoting-Data-in-SQL-1024x1024.png\" alt=\"Five.Co - A SQL pivot transforms rows into columns\" class=\"wp-image-3046\" style=\"width:407px;height:auto\" srcset=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivoting-Data-in-SQL-1024x1024.png 1024w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivoting-Data-in-SQL-300x300.png 300w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivoting-Data-in-SQL-150x150.png 150w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivoting-Data-in-SQL-768x768.png 768w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivoting-Data-in-SQL.png 1080w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Pivot Tables in SQL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s design a database for global smartphone sales to better understand how pivoting tables can help us extract insights from our dataset.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our database has five fields (and many more in reality):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>GUID, which serves as the table&#8217;s Primary Key. For the sake of simplicity, let&#8217;s use simple numbers as the primary key.<\/li>\n\n\n\n<li>Brand<\/li>\n\n\n\n<li>Manufacturer<\/li>\n\n\n\n<li>Model<\/li>\n\n\n\n<li>Month<\/li>\n\n\n\n<li>Units Sold<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is what our database table would look like with five records in it:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>GUID<\/strong><\/td><td><strong>Brand<\/strong><\/td><td><strong>Manufacturer<\/strong><\/td><td><strong>Model<\/strong><\/td><td><strong>Month<\/strong><\/td><td><strong>Units Sold<\/strong><\/td><\/tr><tr><td>1<\/td><td>Apple<\/td><td>Foxconn<\/td><td>iPhone X<\/td><td>January<\/td><td>500<\/td><\/tr><tr><td>2<\/td><td>Samsung<\/td><td>Samsung Electronics<\/td><td>S22<\/td><td>January<\/td><td>2000<\/td><\/tr><tr><td>3<\/td><td>Xiaomi<\/td><td>Xiaomi<\/td><td>Mi 11<\/td><td>December<\/td><td>4500<\/td><\/tr><tr><td>4<\/td><td>Apple<\/td><td>Foxconn<\/td><td>iPhone 14 Plus<\/td><td>July<\/td><td>5000<\/td><\/tr><tr><td>5<\/td><td>Samsung<\/td><td>Samsung Electronics<\/td><td>A55<\/td><td>December<\/td><td>4500<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Even with a small dataset like this, it is difficult to figure out the total monthly number of units sold by model. By pivoting our table, we can create a data view that shows monthly sales by model. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what we would like our final result to look like. By pivoting our tables, we have moved our month records into the column names, transforming rows into columns. We can now clearly see which model is the best-selling smartphone model by month. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img width=\"1024\" height=\"325\" src=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-1-1024x325.png\" alt=\"Five.Co - Result of SQL Pivot\" class=\"wp-image-3041\" srcset=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-1-1024x325.png 1024w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-1-300x95.png 300w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-1-768x244.png 768w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-1-1536x488.png 1536w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-1.png 1964w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the steps we took:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Step 1: We created a simple database table for smartphone sales.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img width=\"1024\" height=\"917\" src=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-2-1024x917.png\" alt=\"\" class=\"wp-image-3042\" style=\"width:351px;height:auto\" srcset=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-2-1024x917.png 1024w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-2-300x269.png 300w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-2-768x688.png 768w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-2.png 1324w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Step 2. We populated the table with the dummy data shown above. Here&#8217;s what our table looks like when writing a <code>SELECT *<\/code> statement.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img width=\"1024\" height=\"431\" src=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-3-1024x431.png\" alt=\"Five.Co - Select * From produces this output\" class=\"wp-image-3043\" srcset=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-3-1024x431.png 1024w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-3-300x126.png 300w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-3-768x323.png 768w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-3-1536x646.png 1536w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-3-2048x861.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">Step 3. To see each model&#8217;s monthly sales we wrote this SQL query, which pivots the table. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>SELECT\n  `SmartphoneSale`.`Model` As Model,\n  SUM(CASE WHEN month = 'January' THEN UnitsSold ELSE 0 END) AS January,\n  SUM(CASE WHEN month = 'July' THEN UnitsSold ELSE 0 END) AS July,\n  SUM(CASE WHEN month = 'December' THEN UnitsSold ELSE 0 END) AS December\nFROM\n  `SmartphoneSale`\nGROUP BY Model<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #98C379\">`SmartphoneSale`<\/span><span style=\"color: #ABB2BF\">.<\/span><span style=\"color: #98C379\">`Model`<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">As<\/span><span style=\"color: #ABB2BF\"> Model,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #56B6C2\">SUM<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #C678DD\">CASE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">WHEN<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">month<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;January&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">THEN<\/span><span style=\"color: #ABB2BF\"> UnitsSold <\/span><span style=\"color: #C678DD\">ELSE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">0<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> January,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #56B6C2\">SUM<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #C678DD\">CASE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">WHEN<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">month<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;July&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">THEN<\/span><span style=\"color: #ABB2BF\"> UnitsSold <\/span><span style=\"color: #C678DD\">ELSE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">0<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> July,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #56B6C2\">SUM<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #C678DD\">CASE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">WHEN<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">month<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;December&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">THEN<\/span><span style=\"color: #ABB2BF\"> UnitsSold <\/span><span style=\"color: #C678DD\">ELSE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">0<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> December<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">FROM<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #98C379\">`SmartphoneSale`<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">GROUP BY<\/span><span style=\"color: #ABB2BF\"> Model<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">In this query, we first select each model and then ask SQL to sum up monthly sales by using a <code>CASE <\/code>statement for each month in our dataset. The corresponding output is exactly what we wanted: a list of smartphones and their monthly sales.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a Web Front End For a SQL Database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We used Five to create the database and write the SQL query above. Five is a rapid application development environment for creating data-driven business software. Each app developed in Five comes with its own MySQL database and an auto-generated admin panel front-end.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what our SQL pivot query looks like as a data view in our app. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img width=\"1024\" height=\"440\" src=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-4-1024x440.png\" alt=\"Five.Co - Admin Panel Web App Containing our SQL Pivot as a data view\" class=\"wp-image-3044\" srcset=\"https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-4-1024x440.png 1024w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-4-300x129.png 300w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-4-768x330.png 768w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-4-1536x660.png 1536w, https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/image-4-2048x881.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Five is the fastest way to go from database to web app. <a href=\"https:\/\/preview-php85.dzine.org\/five\/get-started\/\">Sign up for a free trial<\/a> to start developing today here.<\/p>\n\n\n\n<div style=\"background-color: #001524;\"><hr style=\"height: 5px;\" \/>\n<pre style=\"text-align: center; overflow: hidden; white-space: pre-line;\"><span style=\"color: #f1ebda; background-color: #4588d8; font-size: calc(18px + 0.390625vw);\"><strong>Go From SQL Database to Web App<\/strong><br \/><span style=\"font-size: 14pt;\">Start Developing<\/span><\/span><\/pre>\n<p style=\"text-align: center;\"><a href=\"https:\/\/preview-php85.dzine.org\/five\/get-started\" target=\"_blank\" rel=\"noopener\" data-wplink-edit=\"true\"><button style=\"background-color: #f8b92b; border: none; color: black; padding: 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 18px; cursor: pointer; margin: 4px 2px; border-radius: 5px;\"><strong>Get Instant Access<\/strong><\/button><br \/><\/a><\/p>\n<hr style=\"height: 5px;\" \/><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Pivoting tables in SQL is a common task for programmers, database administrators (DBAs), data analysts or anyone else querying SQL databases. In SQL, a pivot is used to transform (or pivot) rows of data into columns to generate insights from our data. Let&#8217;s learn how to pivot a table in SQL. We will illustrate how [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3045,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[21],"tags":[],"class_list":["post-3039","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"uagb_featured_image_src":{"full":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivot-Tables-in-MySQL.png",1280,720,false],"thumbnail":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivot-Tables-in-MySQL-150x150.png",150,150,true],"medium":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivot-Tables-in-MySQL-300x169.png",300,169,true],"medium_large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivot-Tables-in-MySQL-768x432.png",768,432,true],"large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivot-Tables-in-MySQL-1024x576.png",1024,576,true],"1536x1536":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivot-Tables-in-MySQL.png",1280,720,false],"2048x2048":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/06\/Five.Co-Pivot-Tables-in-MySQL.png",1280,720,false]},"uagb_author_info":{"display_name":"Dominik Keller","author_link":"https:\/\/preview-php85.dzine.org\/five\/author\/f1v5_ed3_my\/"},"uagb_comment_info":0,"uagb_excerpt":"Pivoting tables in SQL is a common task for programmers, database administrators (DBAs), data analysts or anyone else querying SQL databases. In SQL, a pivot is used to transform (or pivot) rows of data into columns to generate insights from our data. Let&#8217;s learn how to pivot a table in SQL. We will illustrate how&hellip;","_links":{"self":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/3039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/comments?post=3039"}],"version-history":[{"count":1,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/3039\/revisions"}],"predecessor-version":[{"id":17809,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/3039\/revisions\/17809"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media\/3045"}],"wp:attachment":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media?parent=3039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/categories?post=3039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/tags?post=3039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}