Wednesday, 7 October 2009

Writing Sql Reports

writing sql reports"writing sql reports"
Moderately difficult SQL/PHP question?

Okay so I'm trying to write a PHP script extracting from MySQL where I take data from two days from one user and compare the days.

From a certain table (call it TableA), I first need to get the days (I have the PHP code to get the dates dynamically, making it a non-issue here). Essentially, a query selecting the user and a certain day's total (call it total) where the date is a certain day (say, '2010-05-04').

Then I need to run another one, same thing, except '2010-05-03'

Then I need to join these two at user, and report their totals from each day in one column. From there, I can perform the calculations I need to run the correct report.

So is it possible to store the result of a query in PHP for later use?
Jeroonk:

Example

User Date #
Bob 2010-05-04 200
Bob 2010-05-03 150
Jim 2010-05-04 432
Jim 2010-05-03 500

To become:
Bob 150 200
Jim 500 432

Make sense?


Join the table with itself like so:

SELECT a.user AS user, a.total AS total1, b.total AS total2
FROM someTable a, someTable b
WHERE a.user = b.user
AND a.date = AND b.date =


ASP.NET 3.5 LINQ TO SQL PART1 : Overview









writing sql reports
writing sql reports
writing sql reports

No comments:

Post a Comment