MySQL Sum Record Values

In this post I will show you an easy way to group and sum values in records. The most trivial example would be when you have a table of address records and you want to count how many people are from each state:

SELECT `state`, count( `state` ) AS num FROM `records` GROUP BY `state` ORDER BY `num` DESC

You could use a similar syntax to sum the distinct values in any field and count them.

  • Digg
  • TwitThis
  • del.icio.us
  • Netvouz
  • description
  • Reddit
  • Furl
  • NewsVine
  • Simpy
  • Slashdot
  • Spurl
  • StumbleUpon
  • YahooMyWeb
  • TailRank
  • Technorati
  • Facebook
  • Google
  • LinkedIn
  • Live
  • MySpace
  • Ping.fm
  • Yahoo! Buzz
  • E-mail this story to a friend!



Home | MySQL | MySQL Sum Record Values