Cherry25 Posted October 23, 2012 Report Posted October 23, 2012 Na table lo 3state fiels unnayi Property. Room. Rank Abc. Tyy. 1 Abc. Tyx. 2 Abc. Hhh. 3 Gri. Tyy. 1 Gri. Aha. 7 Depending on property and room we choose a rank.based on that rank how to find the room with next higher rank for the same property. Note; ranks are not consecutive
padmasri123 Posted October 23, 2012 Report Posted October 23, 2012 Neeku em kavalo knchm telugu lo adugu clear ga!!!
ChampakDas Posted October 23, 2012 Report Posted October 23, 2012 since you said you are choosing the rank that means you know the rank value...as ranks are always incremented by + just do +1 and search..something like this SELECT * FROM TABLE WHERE RANK =@Rank +1 -- @Rank has the value that you searched..
cherlapalli_jailer Posted October 23, 2012 Report Posted October 23, 2012 [quote name='ChampakDas' timestamp='1351018362' post='1302677481'] since you said you are choosing the rank that means you know the rank value...as ranks are always incremented by + just do +1 and search..something like this SELECT * FROM TABLE WHERE[b] RANK =@Rank +1[/b] -- @Rank has the value that you searched.. [/quote] rank >=@rank+1
padmasri123 Posted October 23, 2012 Report Posted October 23, 2012 akkada ranks are not consecutive ani ichadu note lo....
Cherry25 Posted October 23, 2012 Author Report Posted October 23, 2012 [quote name='ChampakDas' timestamp='1351018362' post='1302677481'] since you said you are choosing the rank that means you know the rank value...as ranks are always incremented by + just do +1 and search..something like this SELECT * FROM TABLE WHERE RANK =@Rank +1 -- @Rank has the value that you searched.. [/quote] ranks are not incremental..some properties have ranks like 1,2,10 some have like 5,7,10. Whay to do in this scenario
ChampakDas Posted October 23, 2012 Report Posted October 23, 2012 nope [quote name='cherlapalli_jailer' timestamp='1351018462' post='1302677495'] rank >=@rank+1 [/quote] karma...1min thinking [quote name='padmasri123' timestamp='1351018564' post='1302677509'] akkada ranks are not consecutive ani ichadu note lo.... [/quote]
ChampakDas Posted October 23, 2012 Report Posted October 23, 2012 SELECT TOP(1) Property, room, Rank FROM TABLE where RANK <> @Rank and Property = @property group by Property order by rank edhi chudu mitrama tondaraga confirm chesthey velli bobbunta
roome6 Posted October 23, 2012 Report Posted October 23, 2012 my 2 cents, Sql Gurinchi anta deep ga teliyadhu baa. but, from the concepts, Case and Correlated Sub Queries use avutayi emo nee case lo. naa ideas tho nee time waste chesthonte...
padmasri123 Posted October 23, 2012 Report Posted October 23, 2012 select property,room from @table where rank=@rank group by property,room order by property,room
ChampakDas Posted October 23, 2012 Report Posted October 23, 2012 wrong vayya this will return the room and property that is already selected....top 1 theskovali see my previous post [quote name='padmasri123' timestamp='1351019055' post='1302677569'] select property,room from @table where rank=@rank group by property,room order by property,room [/quote]
padmasri123 Posted October 23, 2012 Report Posted October 23, 2012 [quote name='ChampakDas' timestamp='1351019306' post='1302677603'] wrong vayya this will return the room and property that is already selected....top 1 theskovali see my previous post [/quote] emo vayya naaku aa question ardam kaledu....ardaminanthalo adi cheppanu..
lolliman Posted October 23, 2012 Report Posted October 23, 2012 [color=#8A4A0B]SELECT[/color][color=black] l[/color][color=#145680].[/color][color="#000000"]property[/color][color=#145680],[/color][color=black] l[/color][color=#145680].[/color][color="#000000"]rank[/color][color=#145680],[/color][color=black] r[/color][color=#145680].rank[/color][color=black] [/color][color=#8A4A0B]FROM[/color][color=black] table_name [/color][color=#8A4A0B]AS[/color][color=black] l [/color][color=#8A4A0B]LEFT[/color][color=black] [/color][color=#8A4A0B]JOIN[/color][color=black] table_name [color=#8A4A0B]AS[/color] r [color=#8A4A0B]ON[/color] l[color=#145680].property[/color] [color=#145680]=[/color] r[color=#145680].property[/color] [/color][color=black] [/color][color=#8A4A0B]WHERE[/color][color=black] l[/color][color=#145680].rank[/color][color=black] [/color][color=#145680]<[/color][color=black] r[/color][color=#145680].rank[/color][color=black] [/color][color=#8A4A0B]ORDER[/color][color=black] [/color][color=#8A4A0B]BY[/color][color=black] l[/color][color=#145680].property[/color][color=black] [/color][color=#8A4A0B]ASC[/color][color=#145680],[/color][color=black] l[/color][color=#145680].rank[/color][color=black] [/color][color=#8A4A0B]ASC[/color][color=#145680];[/color]
Recommended Posts