Im taking DBMS course this semester and i want to be sure that im doing good progress and practice good thinking, my own approach for dealing with a query is kinda like divide and conquer - i split the query to sub queries and make them views, then using those views to simply collect the info i need, in general, is it a good approach?
what are the alterantives?
whats your own approach? if you think it is better then mine, why?
EXAMPLE :
GIVEN : DB : http://sqlfiddle.com/#!2/cdd98/1
(Q7) Find patients who visited all orthopedists (specialty) associated with their Insurance Companies.
.
CREATE VIEW Orthos AS
SELECT d.cid,d.did
FROM Doctors d
WHERE d.speciality='Orthopedist';
CREATE VIEW OrthosPerInc AS
SELECT o.cid, COUNT(o.did) as countd4i
FROM Orthos o
GROUP BY o.cid;
CREATE VIEW OrthoVisitsPerPat AS
SELECT v.pid,COUNT(o.did) as countv4d
FROM Orthos o,Visits v,Doctors d
WHERE o.did=v.did and d.did=o.did
GROUP BY v.pid,d.cid;
SELECT p.pname,p.pid,p.cid
FROM OrthoVisitsPerPat v, OrthosPerInc i,Patient p
WHERE i.countd4i = v.countv4d and p.pid=v.pid and p.cid=i.cid