select sum(f1) from ( select f1 from tt1 union select f1 from tt2 ...)
为什么我这样写 $r=select sum(f1) as ff from (select f1 from t1 where s='$s' union select f1 from t2 where s='$s'); echo mysql=result($r,0,'ff'); 不能输出结果,提示mysql_result();supplied argument is not a valid mysql result resource in ....line 2
用union all 将表联合起来
用union all 也是提示上面的错误信息,请问到底是怎么回事啊,代码如何写呢?
在MYSQL中运行上述SQL语句,看看有无问题
是在mysql command line client中运行吗?
是,也可以在SQLYOG等等图形化工具中运行
不好意思,没用过这个。我在mysql command line client 中运行select * from t1,然后下面怎么输出结果呢。
在mysql 命令行可以这样select sum(f1) from t1 union select sum(f1) from t2 联合查询,也能显示结果,但是用下面的就不行了 $r=select sum(f1) from (select f1 from t1 union select f1 from t2 );
TRY: select sum(f1) from (select f1 from t1 union select f1 from t2 ) A
select f1 from tt1
union
select f1 from tt2
...)
$r=select sum(f1) as ff from (select f1 from t1 where s='$s' union select f1 from t2 where s='$s');
echo mysql=result($r,0,'ff');
不能输出结果,提示mysql_result();supplied argument is not a valid mysql result resource in ....line 2
$r=select sum(f1) from (select f1 from t1 union select f1 from t2 );
select sum(f1) from (select f1 from t1 union select f1 from t2 ) A