SQL - 分组事务还对商店名称进行分组

时间:2016-12-02 19:26:01

标签: mysql sql

SELECT frs_Employee.empnin, empname, COUNT( frs_Payment.empnin ) AS Transaction
FROM frs_Employee, frs_Payment
GROUP BY frs_Payment.empnin

当我编译它时,它给了我相同的名字,但正确的数字。我怎么能让这些名字有所不同?

1 个答案:

答案 0 :(得分:0)

您需要在empnin上加入表格。您还需要将empname添加到GROUP BY。

SELECT frs_Employee.empnin
       , empname
       , COUNT( frs_Payment.empnin ) AS Transaction
FROM frs_Employee, 
INNER JOIN frs_Payment on frs_Payment.empnin = frs_Employee.empnin
GROUP BY frs_Employee.empnin, empname