SQL查询,努力用COUNT()计算实例/出现次数

时间:2014-04-20 14:20:27

标签: mysql sql database oracle11g

我试图计算下面这两张表中的访问次数:

宠物餐桌:

enter image description here

访问表:

enter image description here

这是我的SQL

 SELECT pet_name, pet_type
 FROM pets p
 JOIN visits v
 ON p.petid = v.petid
 SELECT COUNT(petid) AS "NUMBER OF VISITS" FROM visits
 WHERE petid = "PT5"

并且它返回了此错误消息:

 ORA-00933: SQL command not properly ended

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:2)

SELECT p.pet_name, p.pet_type, COUNT(v.petid) AS "NUMBER OF VISITS"
FROM pets p
JOIN visits v ON p.petid = v.petid
WHERE p.petid = "PT5"
GROUP BY p.pet_name, p.pet_type