C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

SQL Select Querry


Posted Date: 22 Nov 2008      Posted By: sabitha      Member Level: Silver     Points: 1   Responses: 4



Hai,
I am using SQL Server2005 database in which I have a table say as below which holds 3 colummn with 6data as below:

S.NO Name Amount
1 A1 10
2 B1 10
3 A1 10
4 C1 10
5 A1 10
6 B1 10

Now in the table above Name A1's TotalAmount is (10+10+10)=30.So I want to write a querry for selecting totalAmount for Name A1. So that it Amount should display 30 for A1 and 20 for B1 and 10 for C1.Please give me a select querry for getting the amount in the expalined way.

Thanks.





Responses

Author: Reach2Shaik    22 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 1

select count(Amount) from tablename where name=A1;

use this query

Don't forget to rate this answer, if it is helpful...
Regards Shaik



Author: Deepika Haridas    22 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 3

select count(Amount) from tablename where name = 'A1';
select count(Amount) from tablename where name = 'B1';
select count(Amount) from tablename where name = 'C1';

Regards,
Deepika



Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Author: shailendra rampal    22 Nov 2008Member Level: BronzeRating: 2 out of 52 out of 5     Points: 1

select sno,name,amount as total amount from <table name> group by name


Author: Sriman N Vangala    23 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 4

The simple solution for this is to make use of the select statement displaying the sum of the amount by grouping the column 'Name'

select Name ,sum(Amount) Amt from table
group by Name

which display the output like this:

Name Amt
A1 30
B1 20
C1 10



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Databases
Previous : COMPARISON BETWEEN SYSTEM DATE AND DATE STORED IN DATABASE
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use