我有两张桌子:
个人:
INDEX, NAME, SURNAME
活性:
INDEX, ACTIVITY, PEOPLE_INDEX
我想要显示:
select PEOPLE_INDEX, count(INDEX) from ACTIVITY group by PEOPLE_INDEX
但不是'PEOPLE_INDEX'我想从'PEOPLE'表中看到NAME和SURNAME。
我该如何撰写查询?
谢谢!
答案 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