我有这样一个表 里边有 A,B两栏。A       B0       b
1       a
2       b
3       c
4       b
5       b
6       d我想选择出 A中 x加上A的值和y取余后的结果 在B中为b的结果 
比如 2加上A的值 和 3取余后的结果在B中为b的结果   也就是选出A中 0,1,3,4,6的结果。求高手指教SQL如何写

解决方案 »

  1.   

    if object_id('[TB]') is not null drop table [TB]
    go
    create table [TB] (A int,B nvarchar(2))
    insert into [TB]
    select 0,'b' union all
    select 1,'a' union all
    select 2,'b' union all
    select 3,'c' union all
    select 4,'b' union all
    select 5,'b' union all
    select 6,'d'select * from [TB]declare @x int
    declare @y intset @x = 2
    set @y = 3select * from TB where a in (select distinct (A+@x)%@y from TB) and b='b'/*A           B
    ----------- ----
    0           b
    2           b(2 行受影响)*/