Camillia
asked on
Sum these rows
I have the SQL statement below and a table. I want to sum up the "totalprice" column and show one row. As it is now...2 rows show up.
This is sample of data:
OfficePrice table
BusinessnameID discount price totalPrice
478 20 100 80
478 10 100 90
SQL Above brings back 2 rows because i have 2 rows in OfficePrice. But i want one row to come back with totalPrice column added as 170
BusinessName Id Name TotalNumOfHCPs ........ price
478 xyz 2 170
This is sample of data:
SELECT
businessnameId = CAST(sd.Id AS VARCHAR(MAX)),
NAME = sd.BusinessName,
TotalNumOfHCPs =(SELECT COUNT(*) FROM dbo.SignupHCProvider WHERE BusinessNameId = sd.id) ,
NumPaidHCPs = (SELECT COUNT(*) FROM dbo.PaymentSubscriptionLog WHERE BusinessNameId = sd.id) ,
UnpaidHCPs = (SELECT COUNT(*) FROM dbo.SignupHCProvider WHERE BusinessNameId = sd.id) -
(SELECT COUNT(*) FROM dbo.PaymentSubscriptionLog WHERE BusinessNameId = sd.id),
website= website,
datecreate= CreateDate,
isnull(p.TotalPrice,10) AS price
FROM dbo.SignupDescription sd
LEFT JOIN dbo.OfficePrice p ON p.BusinessNameId = sd.Id
WHERE sd.Id = 478 -- added for testing to show you how the data looks like
ORDER BY NAME
OfficePrice table
BusinessnameID discount price totalPrice
478 20 100 80
478 10 100 90
SQL Above brings back 2 rows because i have 2 rows in OfficePrice. But i want one row to come back with totalPrice column added as 170
BusinessName Id Name TotalNumOfHCPs ........ price
478 xyz 2 170
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.