Firebird,由外键字段组

时间:2013-11-24 20:38:20

标签: sql

我有两张桌子:

  1. 个人

    INDEX, NAME, SURNAME
    
  2. 活性

    INDEX, ACTIVITY, PEOPLE_INDEX
    
  3. 我想要显示:

    select PEOPLE_INDEX, count(INDEX) from ACTIVITY group by PEOPLE_INDEX
    

    但不是'PEOPLE_INDEX'我想从'PEOPLE'表中看到NAME和SURNAME。

    我该如何撰写查询?

    谢谢!

1 个答案:

答案 0 :(得分:1)

SELECT P.NAME, P.SURNAME, A.PEOPLE_INDEX, COUNT(A.INDEX) AS Cnt
FROM ACTIVITY A INNER JOIN PEOPLE P
ON A.INDEX = P.INDEX
GROUP BY P.NAME, P.SURNAME, A.PEOPLE_INDEX