RE: Help with Sum(), newbie
snip not a sum of all of the firsts. What I do want is a sum of all of the numbers in column 5 where the date is after a certain date, column 3 has done in it, and the url matches a regular expression mysql. How do I do that? SELECT SUM(column5) FROM readdata WHERE processdate '2002-8-31' AND column3 = 'done' AND url REGEXP 'mysql'; Don't include column5 in your query. SUM() summarises a group of data by adding up its totals. If you include column5 outside SUM() in your query you are breaking up your results into one entry for each entry that matches the conditions of the WHERE statement. SUM is still doing its job correctly, but will only be adding together 1 number, which is why SUM(column5) = column5. Does that make sense?? L. - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: Help with Sum(), newbie
snip mysql select first, second, SUM(first) from example group by first; +---+++ | first | second | SUM(first) | +---+++ | 1 | 2 | 1 | | 2 | 3 | 2 | +---+++ 2 rows in set (0.00 sec) If it is not obvious, I want the sum of first, which, by my calculations, should be 3. What am I doing wrong? snip If you would like the result of the query to be the sums of the columns try this: SELECT SUM(first), SUM(second) FROM example; Or alternatively, just the sum from the first column use SELECT SUM(first) FROM example; - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php