现在有这么一个问题 我想一起 统计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表覆盖。。我是小菜鸟 学习中。。 不知道应该怎么处时是好。。(单表查询效率低,这样多表是不是效率更高?)
请各位高手指点一下。
比如
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表覆盖。。我是小菜鸟 学习中。。 不知道应该怎么处时是好。。(单表查询效率低,这样多表是不是效率更高?)
请各位高手指点一下。
解决方案 »
- 这个网站可以设置robots文件吗
- ss
- 急急,请教版主和大家
- 关于ecshop的问题
- syntax error, unexpected T_VARIABLE in E:\wamp\www\chat_speak.php on line 10
- 急!!(菜鸟)怎么才能把两个PHP页面文件放到一个页面里
- 插入数据时,其中有一条不能插入的情况。
- 两张关联表,查找主表有,副表中没有的信息 求!SQL语句??????????????????????????????????
- 买了本书PHP&MySqlWeb数据库应用的书,但是现在下不到例子了!!!
- 好累啊,真想休息几天
- tp5中如何去实现类似淘宝的SKU组合?
- php session 保持会话
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;