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
Answer Posted / 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 |
Post New Answer View All Answers
What is the use of partition by in sql server?
Who is the owner of a schema in ms sql server?
What is difference between rownum and rowid?
What is sub-query in sql server? Explain its properties.
What is lookup override?
Do you know the cursor optimization tips?
why does a sql statement work correctly outside of a user-defined function, but incorrectly inside it? : Sql server administration
What is sql profiler. What are the default templates with it? : sql server database administration
Define self join in sql server joins?
What are the aggregate and scalar functions?
What is key set driven?
What is order of B+tree?
What is partition in sql server?
Can you move the resources after pausing the node? : sql server database administration
Is there any performance difference between if exists (select null from table) and if exists (select 1 from table)?