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

How to rename an existing table with the "sp_rename" stored procedure in ms sql server?

985


Recommend an approach to ensuring that all changes in the remote databases synchronize with the SQL Azure database?

128


How to enable tcp/ip protocol on a sql server?

1114


Tell me what is fill factor?

927


Can select statements be used on views in ms sql server?

1028


If a table does not have a unique index, can a cursor be opened on it?

888


Tell me what is normalization? Explain different forms of normalization?

1001


Explain how to maintain a fill factor in existing indexes?

955


How can windows applications connect to sql servers via odbc?

1086


What is the partitioning method?

993


How can you find out if the current user is a member of the specified microsoft® windows nt® group or microsoft sql server™ role?

1001


How you can minimize the deadlock situation?

1006


in the physical file layout, where should the transaction log be stored in relation to the data file? : Sql server administration

1026


What the different components in replication and what is their use?

932


How to apply cascading referential integrity in place of triggers?

1005