|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
With ROLLUP not accurately summing up rows?
I might've missed something in the explanation on MySQL's documentation as to the proper usage/operation of WITH ROLLUP. My impression is that it would provide me with a summary row, that would provide totals for data generated from a SELECT statement.
Here's the Query: mysql Code:
And the results are obviously not accurate totals: Code:
2009-10-31 | 8 | 14 2009-11-01 | 72 | 149 NULL | 78 | 163 72 + 8 = 78? Maybe according to my high school math teacher, but I've learned since that 2 + 8 = 10, which means... ![]() |
|
#2
|
||||
|
||||
|
try it with COUNT instead of COUNT DISTINCT and see if that gives you a hint
![]() |
|
#3
|
|||
|
|||
|
The problem is that I need the DISTINCT clause for the query to return the results I'm looking for. Without it, the two columns return duplicate results.
If there's a way to get the same type of result that simply adds the total of all columns with no other bias than straight math, I'd be interested in knowing. ![]() |
|
#4
|
||||
|
||||
|
Quote:
![]() |
|
#5
|
|||
|
|||
|
Quote:
Ohhh, wait I get what you mean. So two of the IPs returned from the second day also exist on the first day, so the total of the distinct from each day is actually only 78. So returns to my original question... is there a version of ROLLUP I could use that would instead return the sum of all columns unbiased by the SELECT? |
|
#6
|
||||
|
||||
|
sorry, there is only one version of WITH ROLLUP, and the options are: WITH ROLLUP
|
|
#7
|
|||||
|
|||||
|
Wrap it into another select and apply the rollup to the external one.
Something like sql Code:
__________________
My blog Tutorials about OSS databases, DBMonster ... Contribute to OSS Development, fill bug reports! Developer Shed eSupport Commented my.ini/my.cnf (ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Random data (with a bias) |
|
#8
|
|||
|
|||
|
Quote:
That worked great, thanks! Obviously it's invisible to the naked eye, but does anybody have a good summary on the overhead of wrapping a SELECT inside of a SELECT? Is it negligible or due to the fact that I have to loop through each row anyways is it faster to just stick with counting it inside of PHP? I realize that's probably not as simple as yes or no, given possible factors, but I've only just recently started learning how to write more complex SQL queries to try and reduce the workload on my actual PHP scripts... so I wonder here and there whether I'm actually optimizing things or just placing more load on the SQL server haha... :P |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > With ROLLUP not accurately summing up rows? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|