I'm looking for information to pivot a table in mysql. The bbdd that I have is a bit strange, because the data I have to get from a json of one of the fields. After searching, I managed to execute the following sentence:
select
count(if( json_extract(filters, '$.assembled')= true,json_extract(filters, '$.assembled'),NULL)) as assembled,
count(if( json_extract(filters, '$.osWindows')= true,json_extract(filters, '$.osWindows'),NULL)) as windows,
count(if( json_extract(filters, '$.osMac')= true,json_extract(filters, '$.osMac'),NULL)) as mac,
count(if( json_extract(filters, '$.osLinux')= true,json_extract(filters, '$.osLinux'),NULL)) as linux,
count(if( json_extract(filters, '$.sdCard')= true,json_extract(filters, '$.sdCard'),NULL)) as sdcard,
count(if( json_extract(filters, '$.usb')= true,json_extract(filters, '$.usb'),NULL)) as usb,
count(if( json_extract(filters, '$.ethernet')= true,json_extract(filters, '$.ethernet'),NULL)) as ethernet,
count(if( json_extract(filters, '$.wifi')= true,json_extract(filters, '$.wifi'),NULL)) as wifi,
count(if( json_extract(filters, '$.bluetooth')= true,json_extract(filters, '$.bluetooth'),NULL)) as bluetooth,
count(if( json_extract(filters, '$.integratedDisplay')= true,json_extract(filters, '$.integratedDisplay'),NULL)) as integratedDisplay,
count(if( json_extract(filters, '$.touchableDisplay')= true,json_extract(filters, '$.touchableDisplay'),NULL)) as touchableDisplay,
from bigdata_filtered
And I have obtained the following result:
+-----------+---------+-----+-------+--------+-----+----------+------+-----------+-------------------+------------------+
| assembled | windows | mac | linux | sdcard | usb | ethernet | wifi | bluetooth | integratedDisplay | touchableDisplay |
+-----------+---------+-----+-------+--------+-----+----------+------+-----------+-------------------+------------------+
| 2 | 0 | 0 | 0 | 0 | 0 | 14 | 13 | 0 | 0 | 0 |
+-----------+---------+-----+-------+--------+-----+----------+------+-----------+-------------------+------------------+
Now I need to get something like:
property count
assembled 0
windows 0
mac 0
linux 0
sdcard 0
usb 0
ethernet 14
wifi 13
bluetooth 0
integratedDisplay 0
touchableDisplay 0
I've seen tutorials on how to pivot with mysql, but all the examples are to get the opposite (From what I want to do, show how to get what I already have)
Does anyone think of how I can do it? or know any tutorial that explains this particular case?