总和未显示正确结果

时间:2013-06-02 06:34:37

标签: sql

我有三个名为EasyPaisaTimePayOmni的表,其中Profit字段为EasyPasia (10,10)Omni得到(15,15)TimePay获得(20,20)

  1. EasyPaisa总和利润20
  2. Omni,总和利润30
  3. TimePay,总和利润40
  4. 当我通过此查询获取利润时:

    SELECT 
        Sum(EasyPaisa.Profit) AS Expr1, 
        Sum(Omni.Profit) AS Expr2, 
        Sum(TimePay.Profit) AS Expr3
    FROM 
        EasyPaisa, 
        Omni, 
        TimePay;
    

    它给我的结果加倍实际结果

    1. EasyPaisa利润为40
    2. Omni Profit as 60
    3. TimePay利润为80

1 个答案:

答案 0 :(得分:0)

你在找这个吗?

SELECT 
  (SELECT SUM(Profit) FROM EasyPaisa) Expr1,
  (SELECT SUM(Profit) FROM Omni)      Expr2, 
  (SELECT SUM(Profit) FROM TimePay)   Expr3

输出:

| EXPR1 | EXPR2 | EXPR3 |
-------------------------
|    20 |    30 |    40 |

这是 SQLFiddle 演示。