Using the PIVOT table type

The PIVOT table type allows you to do exactly the reverse operation of the OCCUR table. Let's start by creating a copy of our data in a new table.

CREATE TABLE xvisitors2 (
  year char(4) NOT NULL,
  month char(3) NOT NULL,
  number int(10) NOT NULL
) ENGINE=CONNECT;
INSERT INTO xvisitors2 SELECT * FROM xvisitors;

Now we can create a new PIVOT table:

CREATE TABLE pvisitors ENGINE=CONNECT TABLE_TYPE=PIVOT TABNAME=xvisitors2;

You should now be used to the TABLE_TYPE and TABNAME options, which specify the table type and the source table respectively.

Note

If you have issues when creating this table, and get an Access denied error, please consult the documentation about proxy on non-CONNECT tables at https://mariadb.com/kb/en/mariadb/connect-table-types-proxy-table-type/ ...

Get MariaDB Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.