如何从两个不同的表中获取特定列的总和并打印出来

时间:2015-06-02 12:23:47

标签: mysql

select sum(Qty) AS QUANTITY
from purchase
where ItemName='$iname',
      sum(quantity) AS QUANTITY1
      from dispatch
      where ItemName='$iname';

如果我单独运行此查询,如果我在查询上运行语法错误

,则会得到结果
  

1064 - 来自dispatch where的'sum(Qty)AS QUANTITY1旁边的语法错误   ItemName ='$ iname''Ãla ligne 1

1 个答案:

答案 0 :(得分:0)

作为专栏:

select  
    (select sum(Qty) AS QUANTITY from purchase where ItemName='$iname') AS QUANTITY, 
    (select sum(quantity) AS QUANTITY1 from dispatch where ItemName='$iname') AS QUANTITY1