select * from (select * from (select * from tb where c) where b) where a

解决方案 »

  1.   

    楼上的试过了吗?这是不是SQL语句的嵌套,好像不行啊。。
      

  2.   

    Select sum(x),sum(y) from db where (a) and (b) and (c)
    同时满足a,b,c条件的数据即可,如此简单而已
      

  3.   

    如果同时满足A,B,C不行吗?
    select * from tb where A and b and c
    (其中A=expression(X,Y))
      

  4.   

    to jkoala(魔幻熊)
    什么叫同时满足,什么叫依次满足,
    离散数学上的谓词逻辑的化简公式不就是证明他们之间的等同关系吗?
      

  5.   

    To:dhl2001(暗夜行路) 
    你的意思是他们之间确实是相同的,是吗?
    那么:zzutlink(来溜达)的语句不是太繁了,可以简化吗? 
    select * from (select * from (select * from tb where c) where b) where a  
    ====》》》select * from tb where A and b and c
    是这样的吗?
      

  6.   

    select * from (select tb.field1,tb.field2,sum(tb.x) as x,sum(tb.y) as y from tb where A group by tb.field1,tb.field2)  where B and C
      

  7.   

    TO:kplchx(lcx) 
     我觉得你的回答是非常符合我的想法的,我也准备采用,但我还是有一定疑问,就是到底有没有必要用这样的语句,select * from (select * from (select * from tb where c) where b) where a与 select * from tb where A and b and c 到底是否相同?谢谢!
      

  8.   

    TO:dhl2001(暗夜行路) 
      我不大理解你的意思,你能说的更明确一些吗?谢谢!
      

  9.   

    select * from (select * from (select * from tablename where a) where b) where c
    这方法不知能否。能不能说清楚些,比如参照X,Y 字段统计
      

  10.   

    旁门左道:Select 0 as IType,T,Col1,T.Col2... from TB T where A and B and C
              Union all
              Select 1 as IType,Sum(x) as Col1,0 as Col2,... from TB where A
              Union all
              Select 2 as IType,Sum(y) as Col1,0 as Col2,... from TB where A
    其中列的对应关系取决于实际的应用,然后在前端再处理。
    如果你要的数据集是横向的则为:
    (Select 0 as IType,T,Col1,T.Col2... from TB T where A and B and C) as T1
    inner join      
    (Select 0 as IType,Sum(x) as Coln from TB where A) as T2 on T1.iType=T2.iType
    inner join
    (Select 0 as IType,Sum(y) as Coln+1 from TB where A) as T3 on T1.iType=T3.iType顺便说一句此种用法在应用中应该尽量避免
      

  11.   

    我觉得这真是多余,如果使用3个条件用 AND联接,肯定可以利到正确的结果的