please can anyone answer this query
Table 1 has 2 columns: EmployeeId,Age
Table 2 has 2 columns: EmployeeId, Region
Write SQL to Find the region who has the oldest person
Answer Posted / ramesh babu
Create table #tempempid(Employeeid int,age int)
Create table #tempempregion(Employeeid int,Region varchar
(200))
Insert into #tempempid(Employeeid,age)values(100,25),
(101,35),(103,35),(104,10),(105,12),(106,11),(107,13),
(108,24),(109,22),(110,17),(111,11),(112,25),(113,100) ,
(52,100)
go
Insert into #tempempregion(Employeeid,region)values
(100,'SA'),(102,'SA'),(103,'UK'),(104,'UK'),(105,'PHL'),
(106,'US'),(107,'US'),(108,'US'),(109,'RSA'),(110,'RSA'),
(111,'UK'),(113,'SA'),(52,'CA')
Select T.region,T.Age from
(
Select b.region as Region,a.age as Age,
rank() over(order by age desc) as Rnk
from #tempempid a inner join #tempempregion b on
a.Employeeid=b.Employeeid
)T
Where T.Rnk=1
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What are the properties of sub-query?
Explain about temporary stored procedure?
How do indexes help, types?
What is tempdb database? : SQL Server Architecture
What is the purpose of the master database?
Tell me the phases a transaction has to undergo?
what type of index will get created after executing the above statement? : Sql server database administration
What are binary string data types in ms sql server?
How many types of relations are there between dimension and measure group? : sql server analysis services, ssas
What is purpose of normalization?
What is the main purpose of having conversation group?
How to disconnect from a sql server using mssql_close()?
How many types of attribute relationships are there? : sql server analysis services, ssas
How many categories of functions based their return modes?
What is difference between Datepart() and Datename() in SqlServer?