[thelist] SQL: summing and counting the same field, based on value

Tab Alleman talleman at Lumpsum.com
Tue Jun 13 16:35:05 CDT 2006


?    You mean that on every row you want it to return the Count of type=9?   If that's the case, just use a sub-query of (SELECT COUNT(*) FROM ... WHERE Type=9) for that column.  It'll be the same on every row.

> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org]On Behalf Of Canfield, Joel
> Sent: Tuesday, June 13, 2006 5:22 PM
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] SQL: summing and counting the same 
> field,based on
> value
> 
> 
> > select sum(end - start), count(case type when 9 then 1 else 0 end)
> > from ...
> > group by type
> 
> you and Tab both had a good idea; problem is, it still returns four
> values, it's just that three of them are now zero instead of the real
> count. I need this to return only one value: that for type = 9.
> 
> I'm sorting out a workaround in the script, but I'm still 
> interested in
> how one could do this with SQL
> 
> joel
> -- 
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester 
> and archives of thelist go to: http://lists.evolt.org 
> Workers of the Web, evolt ! 
> 



More information about the thelist mailing list