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 transact-sql language?

0 Answers  


What are the different types of joins and what does each do?

2 Answers  


How to name query output columns in ms sql server?

0 Answers  


What is a group function explain with an example?

0 Answers  


If you are given access to a SQL Server, how do you find if the SQL Instance is a named instance or a default instance?

0 Answers  






Do you think BCNF is better than 2NF & 3NF? Why?

0 Answers   Ernst Young,


Explain about analysis services?

0 Answers  


What is thr feature of change data capture?

0 Answers  


Questions on identity?

2 Answers   Infosys,


How to fetch records from a One to Many relationship table. eg: wanna get details of all orders for a specific customer. (do not want repeatation of master table records for child table records)

2 Answers  


What options are there to delete rows on the publisher and not on the subscriber? : sql server replication

0 Answers  


How to find the latest updated value in a table without sending any parameters to that query

2 Answers  


Categories