分开查询时可以的select count(*) as '总委托数'
from a
where a.date1 >= '20100101' and a.date1 <= '20100831'select count(date2) as '总成交数'
from b
where b.date2 >= '20100101'  and b.date2 <= '20100831'我想联合查询,就出现问题,如何解决select count(*) as '总委托数',count(date2) as '总成交数'
from a,b
where a.date1 >= '20100101' and a.date1 <= '20100831'and
b.date2 >= '20100101'  and b.date2 <= '20100831'

解决方案 »

  1.   


    我想联合查询,就出现问题,如何解决select count(*) as '总委托数',count(date2) as '总成交数'
    from a,b
    where a.date1 >= '20100101' and a.date1 <= '20100831'and
    b.date2 >= '20100101' and b.date2 <= '20100831'表a和表b做了笛卡尔乘积,count(*) as '总委托数'肯定不是仅仅表a的select count(*) as '总委托数',c.num as  '总成交数'
    from a,(
            select count(date2) num
            from b
            where b.date2 >= '20100101' and b.date2 <= '20100831'
           ) c
    where a.date1 >= '20100101' and a.date1 <= '20100831'
    试试吧,不知道对不对
      

  2.   


    select
    from
    (select count(*) as '总委托数'
    from a
    where a.date1 >= '20100101' and a.date1 <= '20100831',
    select count(date2) as '总成交数'
    from b
    where b.date2 >= '20100101' and b.date2 <= '20100831')这样就OK了
      

  3.   


    select
    *
    from
    (select count(*) as '总委托数'
    from a
    where a.date1 >= '20100101' and a.date1 <= '20100831',
    select count(date2) as '总成交数'
    from b
    where b.date2 >= '20100101' and b.date2 <= '20100831')
      

  4.   

    select
    *
    from
    (select count(*) as '总委托数'
    from a
    where a.date1 >= '20100101' and a.date1 <= '20100831',
    select count(date2) as '总成交数'
    from b
    where b.date2 >= '20100101' and b.date2 <= '20100831')
      

  5.   


    select
    *
    from
    (select count(*) as '总委托数'
    from a
    where a.date1 >= '20100101' and a.date1 <= '20100831'),
    (select count(date2) as '总成交数'
    from b
    where b.date2 >= '20100101' and b.date2 <= '20100831')
      

  6.   


    谢谢楼上的各位,但是我还有一个查询select count(date2) as '总成交数',CAST(sum(index1*index2) as char(11)) as '总成交金额'
    from b
    where b.date2 >= '20100101'  and b.date2 <= '20100831'然后上面的3个查询结果还得满足一个条件
    b.temp in (select temp from c where temp='7')比较复杂,呵呵。
      

  7.   

    a表和b表还有c表里面 都有 temp。  要满足temp='7'
      

  8.   


    select 
    (select select count(rowid) 
    from a where a.date1 >= '20100101' and a.date1 <= '20100831') as '总委托数',
    (select count(date2) 
    from b where b.date2 >= '20100101' and b.date2 <= '20100831') as '总成交数'
    from dual
      

  9.   

    select
    总委托数,总成交数,总成交金额
    from
    (select temp,count(*) as '总委托数'
    from a
    where a.date1 >= '20100101' and a.date1 <= '20100831')c
    ,
    (select temp,count(date2) as '总成交数',CAST(sum(index1*index2) as char(11)) as '总成交金额'
    from b
    where b.date2 >= '20100101' and b.date2 <= '20100831') d
    where c.temp=d.temp and c.temp='7';
      

  10.   

    好像不行啊,我用的sybase系统。
      

  11.   

    select 
    (select count(*) 
    from a where a.date1 >= '20100101' and a.date2 <= '20100831') as '总委托数',
    (select count(date2) 
    from b where b.date >= '20100101' and b.date <= '20100831') as '总成交数',
    (select CAST(sum(price*qty) as char(11)) 
    from b where b.date2 >= '20100101' and b.date2 <= '20100831') as '总成交金额'
    from a,b
    where a.no=b.no and  b.no in (select no from d where www like '01________')请指定哪里出错了
      

  12.   

    select 
    (select count(*) 
    from a where a.date1 >= '20100101' and a.date1 <= '20100831') as '总委托数',
    (select count(date2) 
    from b where b.date2 >= '20100101' and b.date2 <= '20100831') as '总成交数',
    (select CAST(sum(price*qty) as char(11)) 
    from b where b.date2 >= '20100101' and b.date2 <= '20100831') as '总成交金额'
    from a,b
    where a.no=b.no and  b.no in (select no from d where www like '01________')
      

  13.   


    select  
    (select count(*)  
    from a where a.date1 >= '20100101' and a.date1 <= '20100831'
    and no in (select no from d where www like '01________')) as '总委托数',
    (select count(date2)  
    from b where b.date2 >= '20100101' and b.date2 <= '20100831'
    and no in (select no from d where www like '01________')) as '总成交数',
    (select CAST(sum(price*qty) as char(11))  
    from b where b.date2 >= '20100101' and b.date2 <= '20100831'
    and no in (select no from d where www like '01________')) as '总成交金额'完成了,谢谢大家,我结贴了