easy select

Posted on 2007-10-18
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
    LVL 16

    Expert Comment

    select count(product) pcnt, product, month(date) from table
    goup by product, month(date)
    LVL 4

    Accepted Solution

    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
    LVL 4

    Expert Comment

    dont forget to change myTable to your own table name

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now