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 sql servers link to other servers?

1028


Why I have to use stored procedures?

982


Name 3 of the features that the sql server built-in function loginproperty performs on standard logins? : sql server security

1050


Tell me what is difference between clustered and non clustered index?

900


Explain indexed views?

929


if no size is defined while creating the database, what size will the database have? : Sql server administration

938


What is the Disadvantage of indexed sequential file.

1029


What do you mean by an execution plan? Why is it used?

955


what is the sql equivaent of the dataset relation object ?

1967


Why can there be only one clustered index and not more than one?

935


What is the impact on other user sessions when creating indexes?

876


What are the different types of Indexes available in SQL Server?

951


How do you rename a table in sql server?

947


What is the difference between NOROW and LOCKROW?

2781


What is the difference between set and select?

1023