mysql sum()两个表

时间:2018-02-13 19:54:20

标签: mysql sum

我一直在努力解决这个问题并且很难过。

我使用的代码是

 SELECT 
      employee.vorname, employee.emp_nr, SUM(az_konto.az) AS Total
    FROM 
      employee, az_konto 
    WHERE  
      az_konto.datum BETWEEN '2018-02-01' AND '2018-02-01' + 
      INTERVAL 1 MONTH - INTERVAL 1 DAY
    AND 
      `employee`.`emp_nr` = `az_konto`.`emp_nr`
    GROUP BY 
      vorname, emp_nr, az  

我得到的结果是:

Frank    01   0.00
Frank    01   4.92
Janine   47   6.69
Janine   47   5.25
Julianne 57   0.18

我想要的是

Frank       01  4.92
Janine      47  11.94
Julianne    57  0.18

提前致谢

1 个答案:

答案 0 :(得分:0)

string.split(',')

中有太多列
GROUP BY

使用SELECT employee.vorname, employee.emp_nr, SUM(az_konto.az) AS Total FROM employee, az_konto WHERE ( az_konto.datum BETWEEN '2018-02-01' AND '2018-02-01' + INTERVAL 1 MONTH - INTERVAL 1 DAY AND `employee`.`emp_nr` = `az_konto`.`emp_nr`) GROUP BY vorname, emp_nr 语法

JOIN