can any one answer this query,thank you in advance
Table 1 has 2 columns: EmployeeId, T shirtsize(values can
be 1,2,3)
Table 2 has 2 columns: EmployeeId, Region
Write SQL to Find the region which has the largest number
of people with Tshirt size=3
Answer Posted / ramesh babu
Create table #temptshirt(empid int,tshirt int)
Create table #tempregion(empid int,region varchar(200))
Insert into #temptshirt(empid,tshirt)values(100,2),(102,4),
(103,5),(104,3),(105,3),(106,3),(107,5),(108,6),(109,3),
(110,4),(111,3)
Insert into #tempregion(empid,region)values(100,'SA'),
(102,'SA'),(103,'UK'),(104,'UK'),(105,'PHL'),(106,'US'),
(107,'US'),(108,'US'),(109,'RSA'),(110,'RSA'),(111,'UK')
Select Top 1 T.region,T.Total
from
(
Select b.region,COUNT(*)[Total] from #temptshirt a inner
join #tempregion b on a.empid=b.empid
Where a.tshirt=3
group by b.region
)T
order by 2 desc
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the main difference between ‘between’ and ‘in’ condition operators?
What is primary key and example?
What is difference statement and preparedstatement?
What is difference between clustered index and non clustered index?
Would you store your query in a ssrs report or a database server? State the reason why?
How much does sql server 2016 cost?
What is left outer join in sql server joins?
Please explain what is “asynchronous” communication in sql server service broker?
How to find Duplicate Records In table?
Explain the difference between delete,drop and truncate in SQL Server?
How to download microsoft sql server 2005 express edition?
How to check parameter value in stored procedure sql server?
What are the differences between having and where clause.
What is schemabinding a view?
You want to use bids to deploy a report to a different server than the one you chose in the report wizard. How can you change the server url?