The query pivots the data in one column so that the data creates one column for each of the corresponding values in the first column. (With help from the MySQL Wizard tutorial).
Here is the code the way it should be:
Code: Select all
select main.`Site`, main.`Date`, main.`Time`,
max(if(SensorName = "WindSpd", value,0)) as `Wind Speed`,
max(if(SensorName = "WindDir", value,0)) as `Wind Direction`,
max(if(SensorName = "WindGust", value,0)) as `Wind Gust`,
max(if(SensorName = "AirTemp", value,0)) as `Air Temp.`,
max(if(SensorName = "Visibility", value,0)) as `Visibility`,
max(if(SensorName = "AirPress", value,0)) as `Air Pressure`,
max(if(SensorName = "BoxTemp", value,0)) as `Box Temp.`
From main
Group by main.`Site`, main.`Date`, main.`Time`;Code: Select all
$QuerySelect = "SELECT main.`Site`, main.`Date`, main.`Time`,
max(if(SensorName = "WindSpd", value,0)) as `Wind Speed`,
max(if(SensorName = "WindDir", value,0)) as `Wind Direction`,
max(if(SensorName = "WindGust", value,0)) as `Wind Gust`,
max(if(SensorName = "AirTemp", value,0)) as `Air Temp.`,
max(if(SensorName = "Visibility", value,0)) as `Visibility`,
max(if(SensorName = "AirPress", value,0)) as `Air Pressure`,
max(if(SensorName = "BoxTemp", value,0)) as `Box Temp.` ";
$QueryFrom = "From main ";
$QueryWhere = "WHERE (main.`Date` BETWEEN '$StartDate' AND '$EndDate') AND main.`SensorName` IN(";
------------etc.---------------Any help on figuring this out would be great.
Thanks.