troubleshooting Question

How to write a sql Query to subtract amount by Category ,data are in 2 tables?

Avatar of hariaspind
hariaspind asked on
Microsoft SQL ServerMySQL Server
2 Comments1 Solution449 ViewsLast Modified:
I have 2 query’s as below, each return 9 category and year1amount and year2amount.Now i need to subtract table A from table B data, category wise and get a result set .Which shows
9 category and year1amount and year2amount correspondingly.



Select 'TableA'
select
      MB.CategoryID,
      Sum(MB.Year1Amount) as Year1Amount,
      Sum(MB.Year2Amount) as Year2Amount
from
      MaintenanceBudget MB
INNER JOIN [Plan] P
On
      MB.Planid=P.ID
Where
      P.PlanVersionId=2
Group by
      MB.CategoryID

Select 'Table B'
select
MPB.CategoryID,
Sum(MPB.Year1Amount) as Year1Amount,
Sum(MPB.Year2Amount) as Year2Amount
from
MaintenanceProjectBudget MPB
Inner join
      MaintenanceProject MP
On
      MPB.ProjectID=MP.ID
Inner join [Plan] P
On
      MP.Planid=P.ID
Where P.PlanVersionId=2
Group by
MPB.CategoryID
Order by MPB.CategoryID
 How to write a sql Query to subtract amount by Category ,data are in 2 tables?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros