how to get the following result

  • Hi All

    I'm new to sql server and I've a problem.I've two table

    table 1 Table 2

    stateID stateName CityID StateID CityName SalesAmoubt

    1 MP 1 2 Jaipur 100

    2 Raj 2 1 Bhopal 300

    3 Kar 3 1 Jabalpur 600

    4 UP 4 4 Noida 200

    5 Ker 5 4 Lucknow 200

    6 5 kochi 400

    7 7 Delhi 500

    8 2 Udaipur 700

    I want a result like this:

    StateID StateName SalesAmount

    1 MP 900

    2 Raj 800

    4 UP 400

    5 Ker 400

  • I'm confused, based on the data provided, how does RAJ get a value of 800? What is it that you're trying to do?

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • in table 2 for all the same state id ,sales amout should be summed up

  • Oh, I think I see. The formatting was WAY off there.

    Take a look at the command GROUP BY. You can perform aggregate operations on your data using that. SUM() would be the first aggregation you'd want.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

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

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