Select all but one entries in a column of a table.

Posted on 2006-04-25
Last Modified: 2012-06-27
I have a table in SQL 2000: Man_Hours
It has 2 columns: Name, Hours
I have (say) 4 entries: Joe, Jane, Joane, Auto
Each of these entries has a 'Hours' associated with them.
I have to make a pie-chart with these values, but I don't want the Auto in my chart.
ID |   Name   | Hours  |
 1 |   Joe       |   20    |
 2 |   Jane     |   13    |
 3 |   Joane   |   22    |
 4 |   Auto     |   60    |
I need a query to select names and hours except Auto.
Question by:n4narik
    LVL 6

    Accepted Solution

    select name , sum(hours)
    from man_hours
    where name <> 'Auto'
    group by name
    LVL 6

    Expert Comment

    Sorry I missed id
    select id, name , sum(hours)
    from man_hours
    where name <> 'Auto'
    group by id,name
    LVL 65

    Expert Comment

    by:Jim Horn
    SELECT Name, Sum(Hours) as myHours
    FROM YourTableName
    GROUP BY Name

    This will add up all hours for these four names, with one record for each name.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    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.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    733 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

    20 Experts available now in Live!

    Get 1:1 Help Now