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
 General SQL Server Forums
 New to SQL Server Programming
 Help with this SQL PLZ?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rv498
Yak Posting Veteran

USA
60 Posts

Posted - 03/03/2014 :  16:05:59  Show Profile  Reply with Quote
- List the name, title, and hire date for AdventureWorks employees
-- whose sales quota for 2008 is higher than the average for all employees for 2008.
-- Be sure to use an appropriate sort.
-- 16 Rows

Error I get is CalendarYear is an invalid column. Well it belongs to C2 table but where in the code I need to declare it in order for computer to recognize it?


SELECT C1.LastName+', '+ C1.FirstName AS FullName, C1.Title, C1.HireDate
FROM dbo.DimEmployee AS C1
JOIN (SELECT AVG(SalesAmountQuota) AS AvgQuota FROM dbo.FactSalesQuota ) AS C2
ON C2.CalendarYear = '2008' AND C2.SalesAmountQuota > C2.AvgQuota

rv498
Yak Posting Veteran

USA
60 Posts

Posted - 03/03/2014 :  16:22:26  Show Profile  Reply with Quote
OK So I revised the code below but I am supposed to get 16 rows returned not 15. Am I doing something wrong or maybe 15 is right?

SELECT C1.LastName+', '+ C1.FirstName AS FullName, C1.Title, C1.HireDate
FROM dbo.DimEmployee AS C1
INNER JOIN dbo.FactSalesQuota AS F
ON F.EmployeeKey = C1.EmployeeKey
JOIN (SELECT AVG(SalesAmountQuota) AS AvgQuota FROM dbo.FactSalesQuota ) AS C2
ON F.CalendarYear = '2008' AND F.SalesAmountQuota > C2.AvgQuota
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

373 Posts

Posted - 03/03/2014 :  18:23:39  Show Profile  Reply with Quote
quote:
Originally posted by rv498

- List the name, title, and hire date for AdventureWorks employees
-- whose sales quota for 2008 is higher than the average for all employees for 2008.
-- Be sure to use an appropriate sort.
-- 16 Rows

Error I get is CalendarYear is an invalid column. Well it belongs to C2 table but where in the code I need to declare it in order for computer to recognize it?


SELECT C1.LastName+', '+ C1.FirstName AS FullName, C1.Title, C1.HireDate
FROM dbo.DimEmployee AS C1
JOIN (SELECT AVG(SalesAmountQuota) AS AvgQuota FROM dbo.FactSalesQuota where CalendarYear = '2008') AS C2
ON C2.CalendarYear = '2008' AND C2C1.SalesAmountQuota > C2.AvgQuota
where C1.CalendarYear = '2008'


Edited by - bitsmed on 03/03/2014 18:25:33
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

373 Posts

Posted - 03/03/2014 :  18:50:34  Show Profile  Reply with Quote
Sorry, forget my previous post, and try this instead:
SELECT C1.LastName+', '+C1.FirstName AS FullName
      ,C1.Title
      ,C1.HireDate
  FROM dbo.DimEmployee AS C1
       INNER JOIN dbo.FactSalesQuota AS F
               ON F.EmployeeKey=C1.EmployeeKey
       INNER JOIN (SELECT F.CalendarYear
                         ,AVG(F.SalesAmountQuota) AS AvgQuota
                     FROM dbo.FactSalesQuota AS F
                    WHERE F.CalendarYear='2008'
                    GROUP BY F.CalendarYear
                  ) AS C2
               ON C2.CalendarYear=F.CalendarYear
              AND C2.AvgQuota<F.SalesAmountQuota
Go to Top of Page

rv498
Yak Posting Veteran

USA
60 Posts

Posted - 03/04/2014 :  01:47:44  Show Profile  Reply with Quote
Thanks a million bitsmed!
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.06 seconds. Powered By: Snitz Forums 2000