现在有这么一个问题  我想一起 统计3个表中的 金额
比如
A表   字段money  (可能有5条记录)
B表   字段money (可能有1条记录)
C表   字段money(可能有3条记录)3个表中  都有相同的money字段  我想多表同时查询  每个表中的money总数。我这么写   查询出来的  不准确select a.money as amoney ,b.money as bmoney, c.money as cmoney from A a, B b, C c where (a.time > $times && a.time < $timed) &&  (b.time > $times && b.time < $timed) && (c.time > $times && c.time < $timed)while(){
$a = $a + $rs['amoney'];
$b = $b + $rs['bmoney'];
$c = $c + $rs['cmoney'];
}因为每个表中的记录数不同,所以导致查询出来的结果不准确。 A表可能会被B或C表覆盖。。我是小菜鸟  学习中。。  不知道应该怎么处时是好。。(单表查询效率低,这样多表是不是效率更高?)
请各位高手指点一下。

解决方案 »

  1.   

    兄弟,这种没有关系的表,我觉得可以联合查询,你看看这个,参考下,试试,
    select SUM(hebi_vote.id) as aid from hebi_vote where id>1 and id<6
    UNION All
    select SUM(hebi_vote_answer.id) as bid from hebi_vote_answer where id>1 and id<6
    UNION All
    select SUM(hebi_vote_question.id) as cid from hebi_vote_question where id>1 and id<6;
      

  2.   

    我想取 bid  怎么办呢  $rs['bid']  这样不行呀