9. Write a query to list a new column with the
difference in temp of the cities Delhi and Mumbai, Mumbai
and Jammu and soon. Consider the following table :
City_id City Temp.
1 delhi 40
2 Mumbai 35
3 Jammu 32
4 Pune 18

Answers were Sorted based on User's Feedback



9. Write a query to list a new column with the difference in temp of the cities Delhi and Mumbai, ..

Answer / milena

Hi here is my sql code, tested and works :

select t.CityName As 'CityName1',t.CityTemp
As 'CityTemp1' ,t1.CityName As 'CityName2',t1.CityTemp
As 'CityTemp2',(t1.CityTemp-t.CityTemp)*(-1) As Difftemp
From Test as t inner join Test As t1
on
t1.CityId=t.CityId+1

Result is :

Delhi 40 Mumbai 35 5
Mumbai 35 Jammu 32 3
Jammu 32 Pune 18 14

If you want to remove the CityTemp1, CityTemp2, you can do
so from select statement. :)

Is This Answer Correct ?    4 Yes 0 No

9. Write a query to list a new column with the difference in temp of the cities Delhi and Mumbai, ..

Answer / pradip jain

select t1.name + ' and ' t2.name , t2.temp -t1.temp from
temp t1
join temp t2 on t2.id=t1.id+1

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More SQL Server Interview Questions

Do you know what is blocking?

0 Answers  


You are designing a database for your human resources department in the employee table, there is a field for social security number, which cannot contain null values if no value is given, you want a value of unknown to be inserted in this field what is the best approach?

0 Answers  


if we have a column (Key) in a table. and values of that column is Key 1 1 1 2 2 3 3 4 4 5 5 5 and we want to show the data after query..like.. 1(3) 2(3) 3(2) 4(2) 5(3) how many times a single term comes..

17 Answers   3i Infotech, Rolta, TCS,


How do I create a partition table in sql server?

0 Answers  


How to drop an existing stored procedure in ms sql server?

0 Answers  






After removing a table from database, what other related objects have to be dropped explicitly?

0 Answers  


Explain sp_configure commands, set commands?

3 Answers  


Do you know what guidelines should be followed to help minimize deadlocks?

0 Answers  


How do I create a trace in sql server?

0 Answers  


explain different types of backups avaialabe in sql server? : Sql server database administration

0 Answers  


What is the sql case statement used for? Explain with an example?

0 Answers  


What does REVERT do in SQL Server 2005?

0 Answers   HCL,


Categories