Author Topic: SQL Query Help again..  (Read 2940 times)

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
SQL Query Help again..
« on: March 04, 2006, 09:50:19 PM »
Ive tried so many variations, and searched the net, just cant figure this out.

I have a query which gathers my 20 most recent successes, below

SELECT * FROM ttm ORDER BY received DESC LIMIT 20.

I would like to get the average wait for those 20 records, but I cant figure out the query.

Thanks!!!

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
SQL Query Help again..
« Reply #1 on: March 04, 2006, 11:50:43 PM »
Whats the data structure?

If you store the wait time for each directly you can do something like:
[code]SELECT *, AVG(delay) FROM ttm GROUP BY ID_ORDER ORDERY BY recieved DESC LIMIT 20[/select]

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
SQL Query Help again..
« Reply #2 on: March 05, 2006, 12:12:47 AM »
That doesnt do exactly what I wanted, maybe I didnt explain it right.  Each record has a wait column.

Lets say I change the query to:

SELECT * FROM ttm ORDER BY received DESC LIMIT 4.

and the wait columns for those 4 records are 100, 200, 300, 400, so the total is 1000, so the average wait would be 250.

Thanks again!