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

What is a user-defined function in the sql server and what is its advantage?

0 Answers  


Explain about the command-line tool SQLCMD?

0 Answers  


Explain encryption of entire databases without the need for application changes in sql server 2008?

0 Answers  


Is SET a SQL Keyword?

4 Answers   BitWise,


HOW TO FIND THE EMPLOYEE DETAILS WHO ARE GETTING SAME SALARY IN EMP TABLE

18 Answers   Infosys, TCS,






What is similarity and difference between truncate and delete in sql?

0 Answers  


Hi, I have a table A which has four rows as follows Table A ------- empname salary ------- ------ A 1000 B 2000 C 3000 A 1000 B 2000 D 5000 I need the following output: empname salary ------- ------ A 1000 A 1000 B 2000 B 2000 Thanks in advance

10 Answers   IBM,


What is the Difference Between Primary and Foreign Key?

0 Answers   Accenture, Deloitte, JPMorgan Chase, Maveric,


Give me any three differences between Truncate and Delete.

0 Answers   Genpact,


Where the sql logs gets stored? : sql server database administration

0 Answers  


What is the difference Between Sql-server 2000 & 2005

3 Answers   Value Labs, Wipro,


How can i Relate Tables in SSIS

0 Answers   HCL,


Categories