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


Please Help Members By Posting Answers For Below Questions

hi, the following are the outputs of sp_spaceused and sp_tempdbspace sp_spaceused ------------ database size unallocated size tempdb 77752.95 MB 28026.99 MB sp_tempdbspace ------------- database size spaceused tempdb 77752.945312 1.007812 the unused space in sp_spaceused is nearly 28 Gb and in sp_tempdbspace is nearly 76 Gb cany any one explain about this output and why its giving different results.

2470


what is datawarehouse?

651


Determine when an index is appropriate?

558


What is the fastest way to permanently delete a 1 million row table named customers?

599


What are the system database in sql server 2005?

556






Can foreign key be duplicate?

632


what are candidate key, alternate key and composite key? : Sql server database administration

496


System variable and temporary variables

1716


do you know how to configure db2 side of the application? : Sql server database administration

596


How to create a stored procedure with a statement block in ms sql server?

574


What is the command used to check locks in microsoft sql server?

545


How to create a user name in a database?

590


How to identify current user in ssrs report?

242


How to rename an existing table with the "sp_rename" stored procedure in ms sql server?

538


Define synonym?

731