Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rv498
Yak Posting Veteran
60 Posts |
Posted - 2014-03-03 : 16:05:59
|
- 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.HireDateFROM dbo.DimEmployee AS C1JOIN (SELECT AVG(SalesAmountQuota) AS AvgQuota FROM dbo.FactSalesQuota ) AS C2ON C2.CalendarYear = '2008' AND C2.SalesAmountQuota > C2.AvgQuota |
|
rv498
Yak Posting Veteran
60 Posts |
Posted - 2014-03-03 : 16:22:26
|
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.HireDateFROM dbo.DimEmployee AS C1INNER JOIN dbo.FactSalesQuota AS FON F.EmployeeKey = C1.EmployeeKeyJOIN (SELECT AVG(SalesAmountQuota) AS AvgQuota FROM dbo.FactSalesQuota ) AS C2ON F.CalendarYear = '2008' AND F.SalesAmountQuota > C2.AvgQuota |
|
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2014-03-03 : 18:23:39
|
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.HireDateFROM dbo.DimEmployee AS C1JOIN (SELECT AVG(SalesAmountQuota) AS AvgQuota FROM dbo.FactSalesQuota where CalendarYear = '2008') AS C2ON C2.CalendarYear = '2008' AND C2C1.SalesAmountQuota > C2.AvgQuotawhere C1.CalendarYear = '2008'
|
|
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2014-03-03 : 18:50:34
|
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 |
|
|
rv498
Yak Posting Veteran
60 Posts |
Posted - 2014-03-04 : 01:47:44
|
Thanks a million bitsmed! |
|
|
|
|
|
|
|