给定:
InsuranceCompanies(cid,姓名,电话,地址)
医生(做、姓名、专业、地址、电话、年龄、cid)
患者(pid、姓名、地址、电话、年龄、性别、cid)
访问次数(vid、did、pid、date、description)
在哪里:
cid - Insurance Company code
did - doctor code
pid - patient code
vid - code of visit
还有一个任务:查找今年访问次数少于所有医生平均访问次数的医生(做了,姓名)。
我的尝试是:
SELECT D.did, D. name
FROM Doctor D,Visit V
WHERE V.did = D.did and D.did = CV.did and CV.visits <
(SELECT AVG ( CV.visits)
FROM (SELECT V1.did AS did,COUNT(V1.vid) AS visits
FROM Visit V1
WHERE V1.date LIKE '%2012'
GROUP BY V1.did) AS CV)