easy select

Posted on 2007-10-18
Medium Priority
Last Modified: 2010-03-19
given a table with 2 cols:
product, date

how would i display the products, product count by month in SQL
Question by:acdagirl
  • 2
LVL 16

Expert Comment

ID: 20103306
select count(product) pcnt, product, month(date) from table
goup by product, month(date)

Accepted Solution

orbitus earned 2000 total points
ID: 20103336
assuming you want the year as well, try...

SELECT datename(month,[date]) as myMonth, year([date]) as myYear, product as myProduct, count(product) as CountOfProducts
FROM myTable
GROUP BY datename(month,[date]), year([date]), product

If you dont care about the year then...

SELECT datename(month,[date]) as myMonth, product as myProduct, count(product) as CountOfProducts
FROM myTable
GROUP BY datename(month,[date]), product

Expert Comment

ID: 20103345
dont forget to change myTable to your own table name

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question