I have an application that I wrote in JavaScript/HTML that utilizes a local machine database. It's a pretty complex problem but I just need help with the SQL query right now. More info on the local JavaScript database class is found here: JavaScript Access database class
The data consists of 3D values and a time component so the database is pretty large though I simplified the data from 200 time steps to 3 for testing. There are multiple values that describe the 3D model so I access different values using drop downs. Unfortunately I don't have a working version I can show anyone because it only works on a local machine. I'm trying to convert this version to a web-style database driven demo that runs off MySQL. I host at FatCow and if you know them you know they have a php-driven MySQL interface.
Data Setup
The way the data is set up, I have several columns that describe the 3D data table is described below. This is for one table called "dat":
- Cell (the unique number for that cell in the matrix)
- XVal (this is the X location inbn the matrix)
- YVal (this is the Y location in the matrix)
- Lift (This is the Z location in the matrix)
- Oct-97 (this is one of three time components with values)
- Oct-07 (this is one of three time components with values)
- Oct-17 (this is one of three time components with values)
There are several tables that are called on to make grids, but let's just focus on the 'dat' table for now
Some data tables are set up similarly with the references XVal and YVal but some only refer to the unique Cell value. With the current application, I take the large columns of data and do a transformation pivot table to create grids of the model. The 3D matrix grid is 36x41x15. These grids are displayed as:
- XY plan view
- XZ cross section
- YZ cross section
I have three SQL queries for each of the grids that work in my local application, but these do not work in MySQL. Keep in mind I'm teaching myself how to do this stuff so I'm a bit inexperienced. Don't kill me if it's an obvious mistake.
SQL Queries that work on local application
For the above three queries, here is what works:
XY grid:
TRANSFORM ROUND(max(dat.[Oct-07]) *100,2) SELECT dat.Yval FROM dat WHERE (((dat.Lift)=7)) GROUP BY dat.Yval ORDER BY dat.Yval DESC , dat.Xval PIVOT dat.Xval;
XZ grid:
TRANSFORM ROUND(max(dat.[Oct-07]) *100,2) SELECT dat.Lift FROM dat WHERE (((dat.Yval)=20)) GROUP BY dat.Lift, dat.Yval ORDER BY dat.Lift DESC PIVOT dat.Xval;
YZgrid:
TRANSFORM ROUND(max(dat.[Oct-07]) *100,2) SELECT dat.Lift FROM dat WHERE (((dat.Xval)=20)) GROUP BY dat.Lift ORDER BY dat.Lift DESC , dat.Yval DESC PIVOT dat.Yval;
The application calls the XVal, YVal or Lift that is needed to display. So in the XY grid, [Oct-07] is a variable in the query as is dat.Lift (a number from 1 to 15).
Similarly in the two other grids, [Oct-07] is a variable in the query as is dat.YVal or dat.XVal respectively.
After I imported the data to MySQL I tried running these queries but they give an error:
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TRANSFORM ROUND( max( dat . [ Oct - 07 ] ) * 100 , 2 ) SELECT dat . Yval FROM da' at line 1
I use the ROUND(MAX(... to return every value of the column and fix the decimal.
I think the problem is in the TRANSFORM statement, but I'm not sure how to translate this and get the same result.
The question is, how can I translate these three queries from the MS Access based query to a MySQL based query?
Thanks for help and insight