Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    11

    Unanswered: Need help with SQL Select statement

    I want to output a table that counts the number of projects that have certain status.
    I am not sure how to do this. Here is an example.

    Table1 - kStatus
    ---------------
    StatusKey, StatusName
    --------------- ---------------
    1 Not Started
    2 In Progress
    3 Late
    4 Completed
    5 Canceled

    Table2 - Project
    ---------------
    ProjectName, StatusKey
    --------------- ----------------
    Security 1
    Email 2
    Database 3
    Game 3
    Programming 5
    Internet 3

    Result Table
    -------
    StatusName, TotalProjectStatusCount
    ----------------------------------------------
    Not Started 1
    In Progress 1
    Late 3
    Completed 0
    Canceled 1


    What is the SELECT statement in order to generate this output?

    HELP!!!

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT s.StatusName
         , COUNT(p.StatusKey) AS TotalProjectStatusCount
      FROM kStatus AS s
    LEFT OUTER
      JOIN Project AS p
        ON p.StatusKey = s.StatusKey
    GROUP
        BY s.StatusName
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Aug 2006
    Location
    San Francisco, CA
    Posts
    136
    Try SQL Server Books Online (BOL) and look at table "join", "group by", and "count"
    Last edited by Reghardt; 08-02-10 at 21:39.

  4. #4
    Join Date
    Jul 2010
    Posts
    11
    Thank you!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •