有两个库A,B库A下面有表a,有字段id,value库B下面有表b,有字段id,type
其中表a与表b中的id是相同的
现在想统计表a中,value为1并且id在表b中type为1的数量这个跨库查询语句该怎么写?

解决方案 »

  1.   

    假设在同1服务器中
    select * from a.a a1 inner join b.b b1 on a1.id=b1.id
    where a1.value=1 and b1.type=1
      

  2.   

    如不在同1服务器中,建立FEDERATED引擎表,再用上述代码
      

  3.   

    select count(*)
    from A.a T1,B.b T2
    where T1.id=T2.id and T1.value=1 and T2.type=1
      

  4.   

    假设在同1服务器中
     select count(*) from a.a a1 inner join b.b b1 on a1.id=b1.id
     where a1.value=1 and b1.type=1