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
Can foreign key be deleted?
How to drop an existing user defined function in ms sql server?
How do you know if sql server is running on your local system?
When does a workload on SQL Azure get throttled?
What is read uncmmited?
Does view occupy space?
What are “lock” hints?
How and why use sql server?
Explain the functionalities that views support?
What is single-user mode and what are the steps you should follow to start sql server in single-user mode?
Does sql server 2000 full-text search support clustering?
How can you set the threshold at which sql server will generate keysets asynchronously?
Explain the categories of stored procedure?
What are the restraints imposed on the table design by a merge replication?
Are semicolons required at the end of sql statements in sql server 2005?