group by

  • hi

    i have following query

    select id,

    name,

    value -- its actually total sum for each id

    from table A

    group by

    id,

    name

    value

    here i dont want to use value as it will not get me correct data.how can i avoid it

  • coool_sweet (10/21/2016)


    hi

    i have following query

    select id,

    name,

    value -- its actually total sum for each id

    from table A

    group by

    id,

    name

    value

    here i dont want to use value as it will not get me correct data.how can i avoid it

    If your code is actually does the sum remove value from the group

    select id,

    name,

    sum (value) as idsum

    from table A

    group by

    id,

    name

    If you just want the sum by ID and not Name then that is a different problem.

  • my table already stored value of sum(value) as a value

    i just need to take value ,so i cannot do sum(value) in my select statement

  • If value isn't correct and SUM(value) isn't correct, it's not clear what IS correct without sample data and expected results. Please read the first link in my signature to show how to post the data to the forum. You need to make sure that you're posting enough info to demonstrate the problem without overwhelming people. Based on your question, you probably don't need more than 10 rows.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Who knows, maybe this?

    select id, name,

    max(value) as value

    from table A

    group by

    id,

    name

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

Viewing 5 posts - 1 through 4 (of 4 total)

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