SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Another Query Problem

    Yup...I just keep on screwing up. Any ideas on what's wrong with this one?

    Code:
    SELECT q.quizid, q.quiztitle, q.description, r.totalcorrect,
    SUM(r.totalcorrect) as correct, COUNT(r.resultid) AS total
    FROM quizzes q, results r WHERE r.quiz_id = q.quizid AND q.approve
    = 'Yes' AND r.complete = 'Yes'
    I was also trying to use AVG(), and perhaps a GROUP BY (or at least ORDER BY) statement in there, too, but I can't even get THIS to work, so I'll save that part for later.

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    Dallas/Ft. Worth
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    re:

    What is the error? Syntax seems OK assuming that your have all of those columns in the tables that are named the same way.

    Suggestion...build your query step by step, don't just write the whole thing at once. Start with one table and one comparison, then add second table and another comparison, then do your join.

    Good luck!

  3. #3
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You cannot use AVG without a GROUP BY clause.

  4. #4
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Double-tap!

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And I just erased my message that said that Matt, I reread his post and saw SUM() and didn't even think to rea dthe words where he did indeed use AVG().
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, I found some other error in my logic...d'oh! Thanks anyway, guys.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •