View Single Post
  #1 (permalink)  
Old October 16th, 2006, 04:26 PM
lethe lethe is offline
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Default sql query to generate counts by month

I have a database table with a bunch of transactions. Each transaction has a company and date associated with it. I want to generate a table which has 12 columns, one for each month, and a row for every company. I want each entry to be the number of transactions in the column month with the row company. Also a 13th column with the total for the year for the company, and a final row with the total for the column month across all companies.

Simple little spreadsheet, but I can't figure out how to get there. I think I need to GROUP BY the companies. GROUP BY Company and SELECT COUNT(Transaction number) will give me one column with all the transactions of the company ever. I really need a count function which counts only those matching some month.

Can you help me?

I'm using MS SQL 2000.

thanks in advance
Reply With Quote
The Following User Says Thank You to lethe For This Useful Post:
moorecreative (April 11th, 2015)