Counting Field Values based on another field value

  • How do I achieve the following summary

    =========================================================================

    Project_TypeProject NumberCustomerExpected DateActual Date

    AF-11-02348George8/1/20128/21/2012

    AF-11-01718George8/31/201210/4/2012

    AF-11-03542George8/8/20126/26/2012

    BM-11-07056Tom9/2/20128/15/2012

    BM-11-09207Tom9/29/20126/28/2012

    CD-12-22469Dora8/31/20128/8/2012

    CD-11-22049Dora8/18/20129/7/2012

    CD-11-22049Dora9/30/20129/27/2012

    CD-12-22469Dora10/1/20129/21/2012

    Project Types Summary

    Total Number of Type A Projects 3

    Total Number of Type B Projects 2

    Total Number of Type C Projects 2

    Total Number of Type D Projects 0

    Total Number of Type EProjects 0

    Total Number of Type F Projects 0

    Total Number of Type G Projects 0

    Total Number of Projects7

    =====================================================

    My code is working well except when I only have one entry for a certain Project_Type, then it returns a 0 for the total number of that particular project_Type in the summary

  • Thats great, you posted sample data.

    Can you please take a few minutes create a script that put the data in a Table or create a crude cte just so we have something to work with.

    Please Read.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

    Using your data as the example.

    ;WITH MyTable ([Project_Type], [Project Number], [Customer], [Expected Date], [Actual Date]) AS (

    SELECT 'A', 'F-11-02348', 'George', '8/1/2012', '8/21/2012' UNION ALL

    SELECT 'A', ' F-11-01718', 'George', '8/31/2012', '10/4/2012' UNION ALL

    SELECT 'A', 'F-11-03542', 'George', '8/8/2012', '6/26/2012' UNION ALL

    SELECT 'B', 'M-11-07056', 'Tom', '9/2/2012', '8/15/2012' UNION ALL

    SELECT 'B', 'M-11-09207', 'Tom', '9/29/2012', '6/28/2012' UNION ALL

    SELECT 'C', 'D-12-22469', 'Dora', '8/31/2012', '8/8/2012' UNION ALL

    SELECT 'C', 'D-11-22049', 'Dora', '8/18/2012', '9/7/2012' UNION ALL

    SELECT 'C', 'D-11-22049', 'Dora', '9/30/2012', '9/27/2012' UNION ALL

    SELECT 'C', 'D-12-22469', 'Dora', '10/1/2012', '9/21/2012')

    SELECT COUNT(1) AS ProjectQuantity, Project_Type

    FROM MyTable

    GROUP BY Project_Type

    What query are you running to get the results you requested?

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply