SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 AdventureWorks2012:Identify SalesPerson
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gpspreet
Starting Member

8 Posts

Posted - 03/30/2013 :  05:28:57  Show Profile  Reply with Quote
Assignment:
Identify the sales persons who have sales less than $100,000 since beginning of 2008.
Show: Sales person login ID
Order by: Sales person login ID

WorkAround:
SELECT sp.BusinessEntityID,TotalSales = SUM(soh.TotalDue) -- SUM of all sales total amounts FROM Sales.SalesOrderHeader soh NNER JOIN Sales.SalesPerson sp ON soh.SalesPersonID = sp.BusinessEntityID
WHERE soh.OrderDate >= '20080101' -- on all sales since Jan 1, 2008
GROUP BY sp.BusinessEntityID


Issue:- Not able to get LoginID from HR.Employee Table

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 03/30/2013 :  13:08:38  Show Profile  Reply with Quote
where's HR.Employee? you havent even used table in query then how will you get column from it?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gpspreet
Starting Member

8 Posts

Posted - 03/31/2013 :  23:59:21  Show Profile  Reply with Quote
I found the Answer....

SELECT e.LoginID , spp.BusinessEntityID,spp.TotalSales FROM
(
SELECT sp.BusinessEntityID, TotalSales = SUM(soh.TotalDue) -- SUM of all sales total amounts
FROM Sales.SalesOrderHeader soh
INNER JOIN
Sales.SalesPerson sp ON soh.SalesPersonID = sp.BusinessEntityID
WHERE
soh.OrderDate >= '20080101' -- on all sales since Jan 1, 2008
GROUP BY
sp.BusinessEntityID
) spp

INNER JOIN
Person.Person p ON spp.BusinessEntityID = p.BusinessEntityID
INNER JOIN
HumanResources.Employee e ON p.BusinessEntityID = e.BusinessEntityID
WHERE
TotalSales < 100000.0 order by e.LoginID.


Thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/01/2013 :  00:27:05  Show Profile  Reply with Quote
great.. cheers

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000