[thelist] SQL: summing and counting the same field, based on value
Matt Warden
mwarden at gmail.com
Tue Jun 13 14:09:40 CDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Canfield, Joel wrote:
> My table has (among others) fields for type, start, and end.
>
> I need to get the total duration for all four possible types (got that)
> *and* the count where type = 9
>
> the syntax just isn't coming to me
You might have to adjust the date calc for your db:
select sum(end - start), count(case type when 9 then 1 else 0 end)
from ...
group by type
- --
Matt Warden
Oxford, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEjw10rI3LObhzHRMRAoKtAKCXXbwyol4Z6FjDi3/EqmhdI/z59gCfYVab
GGNwsxbemyF6G9q94XKJZ3s=
=kl7v
-----END PGP SIGNATURE-----
More information about the thelist
mailing list