I am converting a database from MS-Access to MySQL (4.0.20).
In MS-Access I had a query as part of the database (normal SQL term is "view" I have learned) as follows:
SELECT Date, A, B, MAX(V) AS MaxV
FROM Table1
GROUP BY Date, A, B
Lets call that query "Query1". Then I had another query (aka: view):
SELECT Date, SUM(MaxV) As TotalV
FROM Query1
GROUP BY Date
We'll call that "Query2". Then I could have my program do the following:
SELECT *
FROM Query2
WHERE Date=MyDate
Since views are not supported in MySQL (until 5.0 is done) and nested select statments are only supported on MySQL 4.1 (which my hosting service has yet to install), then the only way I can think of to accomplish this task is to CREATE a temp table, SELECT INTO, then query it, and then DROP it when done. This is lame! Can anyone come up with a better way?
To clarify, this is what I would do from the query in my program if nested SELECT statments were aloud:
SELECT Date, SUM(MaxV) As TotalV
FROM (
SELECT Date, A, B, MAX(V) As MaxV
FROM Table1
GROUP BY Date, A, B)
WHERE Date=MyDate
GROUP BY A
by: akshah123Posted on 2004-07-28 at 08:26:56ID: 11657536
you will have to write a script that does that for you. Since your mysql does not handle subqueries it does not allow stored procedures. My Idea is that you should write a script in php.
The only way to accomlish your task with MySQL 4.0 is by some sort of php or other script. If you do not know php, i suggest that you acquire report running program called Crystal Report. This is similar to report generation in access but will you to write more complex report from number of different databases.