Skip navigation
Currently Being Moderated

How do I display multiple summary info from a MySQL table

May 13, 2012 3:05 AM

As part of an airshow web site we'd like to know where our visitors came from. So, when people buy tickets we'll ask what their zipcode is and also record how many adults/ children/ toddlers tickets were sold to the party. The result will be a MySQL table containing the following columns Zip, City/St, Adults, Children, Toddlers. CitySt will be looked up when the ticket seller enters the zipcode and stored in the table.

 

I'd like to display a table sorted by CitySt with separate columns showing how many adults/ children/ toddlers came from each CitySt, I only want to show the totals by CitySt and not the individual sales. i can do the details but how do I create the table showing summary info only by CitySt. Something like this

 

Header 1Header 2Header 3Header 4
City STAdultsChildrenToddlers
City 11242
City 28104
City 31060

I can display the individual table rows but how do I display just summary info by city?

 

Thanks,

 

Tony

 
Replies
  • Currently Being Moderated
    May 15, 2012 11:19 AM   in reply to tonybabb

    You need to use the sum aggregate function and the GROUP BY clause.

     

    Select CitySt, sum(Adults), sum(Children), sum(Toddlers) from MyTable
    Group By CitySt

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points