| Author |
Topic |
|
baburk
Posting Yak Master
108 Posts |
Posted - 2008-12-12 : 06:32:55
|
Hi,This is my table structure.CREATE TABLE [dbo].[City] ( [CityID] int IDENTITY(1, 1) NOT NULL, [City] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Line1] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Line2] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Line3] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Line4] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Sequence1] int NULL, [Sequence2] int NULL, [Sequence3] int NULL, [Sequence4] int NULL, PRIMARY KEY CLUSTERED ([CityID]), UNIQUE ([City]))ON [PRIMARY]GOMy data is stored like this I don't know why image is not visible.I have also posted here and it is visiblehttp://sql-server-performance.com/Community/forums/t/29008.aspxAbove is the map. Line are the roads pass through the city.Sequence is the where the road starts and where it ends.If a person wants to travel from city f to Q, we have to look for roads(Line noted in colors) available.For us Road Green is available and wants to travel from Sequence2 from 8 to 1 (the city is E). But we didn't reach Q. We have to look for another road from E which is RED and travel from there and reach the city Q.How to write the query. |
|
|
darkdusky
Aged Yak Warrior
591 Posts |
Posted - 2008-12-12 : 06:58:42
|
| Is this homework? Should this not be in a few tables?I started this but "from Sequence2 from 8 to 1 (the city is E)" confused me.Select * from(select line1,line2,line3,line4 from citywhere cityid >='f' and <='Q') as RoadsAvailablewhere (line1='Green' or line2='Green' or line3='Green' or line4='Green') and ....... |
 |
|
|
darkdusky
Aged Yak Warrior
591 Posts |
Posted - 2008-12-12 : 06:59:43
|
| correction:Select * from(select line1,line2,line3,line4 from citywhere cityid >='f' and cityid<='Q') as RoadsAvailablewhere (line1='Green' or line2='Green' or line3='Green' or line4='Green') and ....... |
 |
|
|
baburk
Posting Yak Master
108 Posts |
Posted - 2008-12-16 : 00:49:18
|
| This is the sample dataINSERT CitySELECT Q, RED, NULL, NULL, 1, NULL, NULL UNION ALLSELECT A, RED, NULL, NULL, 2, NULL, NULL UNION ALLSELECT C, RED, GREEN, NULL, 3, 1, NULL UNION ALLSELECT D, NULL, GREEN, NULL, NULL, 2, NULL UNION ALLSELECT E, NULL, GREEN, BLUE, NULL, 3, 1 UNION ALLSELECT F, NULL, GREEN, NULL, NULL, 4, NULL UNION ALLSELECT G, NULL, NULL, BLUE, NULL, NULL, 2 UNION ALLSELECT H, NULL, NULL, BLUE, NULL, NULL, 3 UNION ALLSELECT J, NULL, NULL, BLUE, NULL, NULL, 4 UNION ALLSELECT K, NULL, NULL, BLUE, NULL, NULL, 5 UNION ALLSELECT L, NULL, GREEN, NULL, NULL, 5, NULL UNION ALLSELECT O, NULL, GREEN, NULL, NULL, 6, NULL UNION ALLSELECT P, NULL, GREEN, NULL, NULL, 7, NULL UNION ALLSELECT X, NULL, GREEN, NULL, NULL, 8, NULLThe map and data are looked like this.[url]http://www.drivehq.com/file/DF.aspx/TableData.JPG?isGallery=&share=&shareID=0&fileID=261175633&sesID=jjwlqv55dfjd1guolgdqnz55&size=pv&ft=12/12/2008%203:15:16%20AM&pay=&n=531[/url]Thanks for the reply. |
 |
|
|
|
|
|