SQL Server Performance


Discussion in 'Getting Started' started by mark01, Aug 14, 2009.

  1. mark01 New Member

    Hi everyone I need help with sql select statement.I have table and in that table some columns have same value like:
    John 23
    Smith 36
    Suzan 21
    John 12
    and I don't know how to write select statement that would add columns with same name and select the other columns too.The result should be
    John 35
    Smith 36
    Suzan 21
    Please help.
    Thanks in advance
  2. madhuottapalam New Member

    You need to use GROUP BY clause..
    check this script
    @tab table (name varchar(20), amt int)insert
    @tab select 'John', 23insert
    @tab select 'Smith', 36insert
    @tab select 'Suzan', 21insert
    @tab select 'John', 12select
    name,sum(amt) as sumamt from @tab group by Name
  3. mark01 New Member

    Thanks to your help I solved my problem.

Share This Page