Jump to content

sql help


vizagpower

Recommended Posts

this is what you should do to get your desired result set man.... 

	SELECT a.BusinessEntityID, SUM(b.SalesLastYear) AS prevYear, SUM(b.SalesYTD) AS YTD
	        , SUM(b.SalesLastYear) + SUM(b.SalesYTD) AS sales
	FROM Sales.SalesPerson a
	INNER JOIN Sales.SalesTerritory b ON a.TerritoryID = b.TerritoryID
	GROUP BY a.BusinessEntityID
	

Link to comment
Share on other sites

group by tharavatha chudhaam.. 

for group by theeseyi...and add the two variables.

 aa summation work aitey...then groupby ni CTE lo cheyochu or direct ga cheyochu

 

chk the summation. I am hoping both sums are INTs and amounts

Link to comment
Share on other sites

2 hours ago, vikuba said:

group by tharavatha chudhaam.. 

for group by theeseyi...and add the two variables.

 aa summation work aitey...then groupby ni CTE lo cheyochu or direct ga cheyochu

 

chk the summation. I am hoping both sums are INTs and amounts

Variables ki enni values pass chesina it will take first value only man. 

For ts, put all d data into a CTE andjoin that to the result set you have currently and get what you want man.. simple and straight forward... good luck.

Link to comment
Share on other sites

4 minutes ago, loveindia said:

Variables ki enni values pass chesina it will take first value only man. 

For ts, put all d data into a CTE andjoin that to the result set you have currently and get what you want man.. simple and straight forward... good luck.

CTE gives clarity - the best. 

but to do this one should have clarity on what he is doing also

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...