ERROR 1241(21000):操作数应包含多个选择中的1列

时间:2012-08-03 07:19:50

标签: mysql

   select
        (select sum(sal)as sal_tp, sum(local_conv) as lc_tp from budget_tp),
        (select sum(sal) from budget_fos_veri) as sal_veri,
        (select sum(sal) from budget_fos_picks)as sal_pick,
        (select sum(sal) from budget_bpo_other)as sal_bpo;

我得到了

ERROR 1241 (21000): Operand should contain 1 column(s).

我的要求有没有办法完成?该查询实际上是一个示例。我有很多具有多列的表,我想查看所有表的各列的总和,我只是尝试在第一行中一次查看两个我得到此错误,如果我尝试只检索一列然后其细

1 个答案:

答案 0 :(得分:4)

每个子查询都应该返回一个字段。试试你的查询 -

   select
        (select sum(sal) from budget_tp) as sal_tp,
        (select sum(local_conv) from budget_tp) as lc_tp,
        (select sum(sal) from budget_fos_veri) as sal_veri,
        (select sum(sal) from budget_fos_picks)as sal_pick,
        (select sum(sal) from budget_bpo_other)as sal_bpo;

另一个:

   select
        (select concat(sum(sal), ',' ,sum(local_conv)) from budget_tp) as sal_tp_and_lc_tp
        (select sum(local_conv) from budget_tp) as lc_tp,
        ...