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
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 |
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 |
How to get max 100 values from sql server
Explain log shipping and mention its advantages.
Define union, union all, minus, intersect?
How to check parameter value in stored procedure sql server?
explain different types of cursors? : Sql server database administration
What is difference between join and natural join?
Name three version of sql server 2000 and also their differences?
Explain the advantages of merge replication?
Why we use the openxml clause?
how to count datewise data in sqlserver
4 Answers CarrizalSoft Technologies, IndusInd Bank,
Can a trigger be created on a view?
Can we delete data from a view?