有2张表
表A                     表B
a    b                  a     c
11    1                 1     0000
50    11                2     0000
34    50            
20    2                     表A是一个循环路径的表,当A.b<10的时候用A.a  =  B.a 取出B.c的值
这个应该实现,大家给点思路

解决方案 »

  1.   

    select b.c from b,a where a.a=b.a and a.b<10--这样?
      

  2.   

    select B.c from A,B where A.a=B.a and A.b<10
    --没看懂
      

  3.   

    select B.c from A,B where A.a=B.a and A.b<10
      

  4.   


    表A的字段是?表B的字段是?还是A和B 的字段一样? 
      

  5.   

    本来打出来是好的我重说一下吧
    表A 有两个字段  a   b
    表B 有两个字段   a   c
    开始的时候我只能得到类似于A.a 中50这样的数据  然后要从A中找到A.b<10对应的A.a,然后用A.a到B中取数据换句话说就是,用A   join  A on  A.b = A.a 然后判断A.b 是否<10 
    不知道是否说清楚了
      

  6.   

    select B.c from A,B where A.a=B.a and A.b<10
    --看了下,貌似还是这样可以解决。
      

  7.   

    我是要找到 50 所对应的 B.c的值  最后得到 50  0000  ,   20  0000这样的结果集,
    所以说select B.c from A,B where A.a=B.a and A.b<10 解决不了
      

  8.   

    那你加这一句是干嘛的,当A.b<10的时候用A.a = B.a 取出B.c的值
    搞我们??
      

  9.   

    ---这样?----------------------------------------------------------------
    -- Author  :fredrickhu(小F,向高手学习)
    -- Date    :2011-08-11 20:54:27
    -- Verstion:
    --      Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86) 
    -- Jul  9 2008 14:43:34 
    -- Copyright (c) 1988-2008 Microsoft Corporation
    -- Enterprise Evaluation Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)
    --
    ----------------------------------------------------------------
    --> 测试数据:[a]
    if object_id('[a]') is not null drop table [a]
    go 
    create table [a]([a] int,[b] int)
    insert [a]
    select 11,1 union all
    select 50,11 union all
    select 34,50 union all
    select 20,2
    --> 测试数据:[b]
    if object_id('[b]') is not null drop table [b]
    go 
    create table [b]([a] int,[c] varchar(4))
    insert [b]
    select 1,'0000' union all
    select 2,'0000'
    --------------开始查询--------------------------
    ;with f as
    (
    select * from a where exists(select 1 from b where a.b=b.a)
    union all
    select a.* from a,f where a.b=f.a)
    select b.c from f,b where f.b=b.a and  f.b<10
    ----------------结果----------------------------
    /*c
    ----
    0000
    0000(2 行受影响)*/