Good afternoon, i want to ask about MySql query.
I have the initial data from first query as pict below (can dymically) base on where clause using this query SELECT company, discipline_name from tb_data WHERE nfc_id <>"" and valid_start = '2023-07-12' group by category ORDER by category asc
.
And from second query i get the data as pict on bellow using this query SELECT company, discipline_name, count(global_id) AS Total from tb_data WHERE nfc_id <>"" and valid_start = '2023-07-12' group by company,category ORDER by category asc;
.
Then the result i wanted like pict on below.
my question is, how to create dynamicaly column like the result i wanted. because the count of column sometimes is changed base on valid_start where clause. Using stored procedure or how?
Thank You, Regards
[pivot-table]
in stackoverflow.com . However, the cross-tabs is not discussed much.SELECTs
to have the same column names as the images.