views:

102

answers:

1

I need to produce a large HTML table with quarterly counts for several (around 50) different groups (jurisdictions). I have a MySQL table with around 16,000 rows which have 'jurisdiction_id' and 'quarter' fields. Unfortunately my client doesn't want the resulting report to be paginated. How would I construct a good MySQL query from which to generate such a table with PHP and HTML? Please see the image for the desired end-result.

Table Name: inspections

Relevant Table Fields:

  • id
  • jurisdiction_id
  • quarter

Image Depicting Desired End Result: http://www.freeimagehosting.net/uploads/8fd7ca2530.png

I'm a SQL newb, so please let me know if you need more information in order to provide a helpful response.

Thank you so much for your help.

+1  A: 

Something like this should be fine:

SELECT jurasdiction_id, quarter, COUNT(*) AS num
FROM inspections
GROUP BY jurasdiction_id, quarter
Greg
Thank you for the response! Would this be a large/taxing query for a table with 20,000 rows? How about 200,000? I don't really have a sense of scale with database performance, so my concern is that I'll bring a web/mysql server to its knees by retrieving a large data set.
20,000 should run fine on any machine. 200,000 is harder to say - the only thing to do is test it and find out
Greg
Great. Thanks very much, Greg.