Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Re: Sum a field

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2010-09-29 : 05:04:40
Hi,

I have a query which called qrypayamountperpatient, when I execute this query I get the result;

Prac_no Amountperpatient

9998 100.00
9998 50.00
1000 86.00

I want to have another select query to read from the above query but giving the results;

Prac_no GrossAmmount

9998 150.00
1000 86.00

Note: Since Prac_no = 9998 is the same then I sum the amountsperpatient, hence 100.00 + 50.00 = 150.00

Any help please!!

Many thanks

Sachin.Nand

2937 Posts

Posted - 2010-09-29 : 05:07:22
[code]Select Prac_no,sum(Amountperpatient)from table group by Prac_no[/code]

PBUH

Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2010-09-29 : 05:11:33
Nice...

One last thing;

What if I have the following;

projectID Prac_no Ampountperpatient
1 9998 100.00
1 9998 50.00
1 1000 86.00
2 9998 115.00
3 7676 450.00

and I would like the result to be;

projectID Prac_no Ampountperpatient
1 9998 150.00
1 1000 86.00
2 9998 115.00
3 7676 450.00

Note, the sum is based if it is from the same ProjectID.

Many thanks

Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-09-29 : 05:31:37
Select projectID,Prac_no,sum(Amountperpatient)from table group by projectID,Prac_no


PBUH

Go to Top of Page
   

- Advertisement -