我现在要查询一个表A,假如用户排名rank=50,单位间隔=3 我想要查询的结果是 在rank之前,也就是排名要在50之前,并且间隔是 3
那么结果是47,44,41,38,35。。谢谢了。

解决方案 »

  1.   

    表A中可以用的字短有userID,rank
      

  2.   

    select rank,* from A where =3 and rank<50 order by rank desc
      

  3.   

    ……select * from A where rank<50 and 单位间隔=3
      

  4.   

    求sql达人给个思路。急啊 
      

  5.   

    select * from A where rank<50 and 单位间隔=3  group by rank DESC--(降序)
      

  6.   


    declare @i int
    set @i = 1
    select @i as userId, @i as rankId into #a
    while @i<60
    begin
    set @i = @i + 1
    insert into #a values(@i,@i)
    endselect * FROM #a where rankid <50 and (rankid+1) %3=0 order by rankid desc
    结果:
    userId rankId
    47 47
    44 44
    41 41
    38 38
    35 35
    32 32
    29 29
    26 26
    23 23
    20 20
    17 17
    14 14
    11 11
    8 8
    5 5
    2 2
      

  7.   

    @i as rankId into #a这个into #a是什么意思哈?谢谢
      

  8.   

    其实是select ... into ...语法 #a是自定义的表明
      

  9.   

    select ... into ...语法   #a就是临时表,对吧,谢谢哈
      

  10.   


      int[] numbers = new int[11] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };            var numQuery =
                    from num in numbers
                    where (num % 3) == 0 && num<9
                    select num;            foreach (int num in numQuery)
                {
                    Console.Write("{0} ", num);
                }
    顺便用linq 试试  
      

  11.   

    declare @rank int =50  ---初始数量 爱多少多少
    declare @arr varchar(300) ----47,44....条件
    declare @sql varchar(2000) ----sql语句
    set @arr=''
    while(1=1)
    begin
    set @rank=@rank-3
    if(@rank<0)
    begin
    set @arr=SUBSTRING(@arr,1,(len(@arr)-1))
    break
    end
    set @arr=@arr+ltrim(@rank)+','
    endset @sql='select * from A where rank in ('+@arr+')'
    --print @sql
    exec(@sql)
      

  12.   

    select * FROM #a where rankid <50 and (rankid+1) %3=0 order by rankid desc
      

  13.   


    select * from A where rank<50 and (50-rank)%3=0需要那么难吗??楼上各位