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 is in place upgrade in sql server?
How to loop through the result set with @@fetch_status?
Why you need indexing? Where that is stored and what you mean by schema object? For what purpose we are using view?
What is thr feature of change data capture?
Is it true that rules do not apply to data already existing in a database at the time the rule is created?
What is subquery in sql?
What are the types of table?
explain what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration
What is the difference between dbcc indexdefrag and dbcc reindex?
Mention the differences between having and where clause.
List out some of the requirements to set up a sql server failover cluster?
what are the basic functions for master, msdb, model, tempdb and resource system databases? : sql server database administration
How to get the definition of a stored procedure back?
What is data mart? : sql server analysis services, ssas
please differentiate between delete and truncate?