We've been getting a lot of SQL questions lately. This stuff is really off topic for a JSP list.
That said, I'll turn off the rant, and answer the question.
If you want to retrieve other values at the same time, you need to use the HAVING clause in order to specify what you are aggregating on (since the sum() function is an aggregate function, meaning that it works on many records, returning a single value).
If you are trying to get a total for the columns, and the list of data. You need to issue the request twice w/ the same WHERE clause, and do the summation separately. In most cases, the fact that this is two queries won't be a problem, if it is you may need to look into setting your transaction level to repeatable read, and issue a start transaction.
Ed Ventura wrote:
How would I incorporate the code into my sql statement below:
SELECT * FROM DOC.BCCHECKLIST WHERE STARTTIMEDATE BETWEEN TO_DATE('varSTARTDATE','mm/dd/yyyy') AND TO_DATE('varENDDATE','mm/dd/yyyy') ORDER BY STARTTIMEDATE DESC
Thanks, Ed.
From: Clayton Nash <[EMAIL PROTECTED]> Reply-To: A mailing list about Java Server Pages specification and reference <[EMAIL PROTECTED]> Date: Tue, 3 Jun 2003 17:01:10 +0100 To: [EMAIL PROTECTED] Subject: Re: Multiplying two columns and then adding up all the records.
Select sum(pagecount*pages)
Clayton ----- Original Message ----- From: "Ed Ventura" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, June 03, 2003 4:58 PM Subject: Multiplying two columns and then adding up all the records.
How do I multiply two columns and then add them all up from a resultset?My
database looks like this:===========================================================================
CLIENT PAGECOUNT PAGES Xyzco 10 1 Abcco 5 3 Defco 3 6
So I need to multiply PAGECOUNT X PAGES for each record and then add them all up to get a total. In this example I would need to multiply (10 x 1) + (5 x 3) + (3 x 6) = grandtotal.
Thanks for any help, Ed.
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoffJSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTERESTDIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
=========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
=========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
=========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
