Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Can foreign key be deleted?

870


How to drop an existing user defined function in ms sql server?

979


How do you know if sql server is running on your local system?

974


When does a workload on SQL Azure get throttled?

129


What is read uncmmited?

1010


Does view occupy space?

884


What are “lock” hints?

998


How and why use sql server?

953


Explain the functionalities that views support?

1043


What is single-user mode and what are the steps you should follow to start sql server in single-user mode?

932


Does sql server 2000 full-text search support clustering?

813


How can you set the threshold at which sql server will generate keysets asynchronously?

938


Explain the categories of stored procedure?

885


What are the restraints imposed on the table design by a merge replication?

982


Are semicolons required at the end of sql statements in sql server 2005?

931