another .jsp question

Homerboy

Lifer
Mar 1, 2000
30,859
4,976
126
Its chocking on the query even if I remove the "WHERE" condition. Am I not using AVG properly?

Thanks
 

Cerebus451

Golden Member
Nov 30, 2000
1,425
0
76
According to the docs, AVG is an aggregate function, meaning that you have to have a GROUP BY column. Add a GROUP BY p.team into your query.

EDIT: After reading it closer, it appears you don't need the GROUP BY (which means perform across all rows), so I'm not sure.

EDIT2: What specific error message is being returned?
 

Homerboy

Lifer
Mar 1, 2000
30,859
4,976
126
Originally posted by: notfred
How is that a JSP question?

er... your right. It is in a .jsp file and I was just POed when I posted and didnt think straight.
 

Homerboy

Lifer
Mar 1, 2000
30,859
4,976
126
Originally posted by: Cerebus451
According to the docs, AVG is an aggregate function, meaning that you have to have a GROUP BY column. Add a GROUP BY p.team into your query.

EDIT: After reading it closer, it appears you don't need the GROUP BY (which means perform across all rows), so I'm not sure.

EDIT2: What specific error message is being returned?


Thats the trick
there is no error msg, just the HTML is choking at that point when I add it to the .jsp file (and if I enter it into mySQLfront as a SQL query).
 

bunker

Lifer
Apr 23, 2001
10,572
0
71
make sure teamid actually has a value in it.

Try running it by substituting an acutal number for the variable.
 

Homerboy

Lifer
Mar 1, 2000
30,859
4,976
126
Originally posted by: bunker
make sure teamid actually has a value in it.

Try running it by substituting an acutal number for the variable.

Well I havent tried that, but I have tried it solely without the "teamid" varialbe in there at all at that craps out too


ResultSet teamovr = stmt.executeQuery("SELECT AVG(ovrl) AS averageovrl FROM players WHERE team = 2")
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 'ResultSet teamovr = stmt.executeQuery("SELECT AVG(ovrl) AS aver
 
Jul 8, 2004
100
0
0
Does the query run outside of the jsp page?

If so, did you check to make sure that the DB connection is working by using a simple statement like "select * from players;"?

The only other thing that jumps out at me right now is you might need to add + ";" after the teamid.
 

Homerboy

Lifer
Mar 1, 2000
30,859
4,976
126
well the example I see on mysql.com shows:

mysql> SELECT student_name, AVG(test_score)
-> FROM student
-> GROUP BY student_name;


so I edited:

ResultSet teamovr = stmt.executeQuery("SELECT ovrl, AVG(averageovrl) FROM players WHERE team = 2 GROUP BY ovrl");

and still errors

 

Homerboy

Lifer
Mar 1, 2000
30,859
4,976
126
Originally posted by: haris
Does the query run outside of the jsp page?

If so, did you check to make sure that the DB connection is working by using a simple statement like "select * from players;"?

The only other thing that jumps out at me right now is you might need to add + ";" after the teamid.

it runs inside the .jsp
I've tried it with completly removing the + teamid and editing with "WHERE team = 2"
 
Jul 8, 2004
100
0
0
Originally posted by: Homerboy
Originally posted by: haris
Does the query run outside of the jsp page?

If so, did you check to make sure that the DB connection is working by using a simple statement like "select * from players;"?

The only other thing that jumps out at me right now is you might need to add + ";" after the teamid.

it runs inside the .jsp
I've tried it with completly removing the + teamid and editing with "WHERE team = 2"

Does a "simple" query like the one I mentioned run at all in the jsp page?

I also asked if you can run the query using another tool that connects to the database? Something like Oracle's SQLPlus or MS's QueryAnalyzer. I used MySQL once awhile back, and I can't remember what built in tool it has for this purpose.
 

Homerboy

Lifer
Mar 1, 2000
30,859
4,976
126
there are other queries already running on the page with no problems (not to mention a few dozen other pages through the site that work n/p)
Ive tried entering the query (with no "teamid") directly into mySQL front and get the error I posted above:

ResultSet teamovr = stmt.executeQuery("SELECT AVG(ovrl) AS averageovrl FROM players WHERE team = 2")
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 'ResultSet teamovr = stmt.executeQuery("SELECT AVG(ovrl) AS aver
 

bunker

Lifer
Apr 23, 2001
10,572
0
71
You'll notice the example from that link does not use AS, get rid of AS like Torpid said.
 

Homerboy

Lifer
Mar 1, 2000
30,859
4,976
126
I did try getting rid of the "AS" and it still crapped.
I can actually just use the stupid "SUM" and simple divide it by 12 (all of them should have 12 variables...if not tough shit). Its not the right way to do it, but since I can't make it work the right way Ill do it any way that works.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: Homerboy
there are other queries already running on the page with no problems (not to mention a few dozen other pages through the site that work n/p)
Ive tried entering the query (with no "teamid") directly into mySQL front and get the error I posted above:

ResultSet teamovr = stmt.executeQuery("SELECT AVG(ovrl) AS averageovrl FROM players WHERE team = 2")
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 'ResultSet teamovr = stmt.executeQuery("SELECT AVG(ovrl) AS aver
The fact that the error message includes java code instead of simply the contents of the string seems really odd. Could you post the stack trace and the section of code surrounding this call?

I'd also recommend taking it to the command line. Whenever there's a query that doesn't work the quickest thing is to get it in a place where you can execute it over and over again quickly. What version of mysql are you running? I have 4.1.3b here and a similar query runs fine.
 

Jack Ryan

Golden Member
Jun 11, 2004
1,353
0
0
You mentioned other queries are running on this page, are you reusing the stmt or are you creating a new one for each call?



Whoops, should read more, I just read you said SUM worked fine.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |