D
|
david powell author 2/24/2024 |
Addendum: I do realise that if I have multiple columns each can be ascribed to a data series. But that would involve with the data I have doing a cross-tab which is not supported by mysql, and I cant do the #case trick because I dont know how many different sites there will be. I am tempted ot convert to sql server which does support cross tabs, but I am not sure if asprunner will be able to handle them anyway so am reluctant to do this quite yet... |
D
|
david powell author 2/24/2024 |
OK, I have created a workaround . Written an sql script that creates a new table as a cross tab with a column for any entries with a specific 'location'. I can then use this table, which is essentially a pivot/crosstab table, a ssource for the chart. This script contains a union to link a current/archive sourcce table, and does a calculation as well on each row. Run as a cron job on the server. -- Set sql_mode to ignore zero dates -- Drop the table if it exists -- Generate dynamic SQL for pivot SELECT -- Create the new table inventory_crosstab SET @sql = CONCAT('CREATE TABLE inventory_crosstab AS SELECT id, ', @sql_created, ', ', @sql_location, ' FROM (SELECT FROM inventory UNION ALL SELECT FROM inventory_archive) AS combined_tables GROUP BY id;'); -- Prepare and execute the dynamic SQL -- Reset sql_mode |
D
|
david powell author 2/25/2024 |
Only problem with this approach is that the charts are static intheir construction, each data item has to be allocated to a value in the query. What would be great is if it could be dynamic, and allow all items in a collection each to be assigned a line, so that it can cope with an unknown number of 'columns'. |