I have a view that contains a number of nested views as shown below.
Main View:
CREATE VIEW `qryAttackRate` AS
Select qryFoodInCases.fldCaseID,qryFoodInCases.fldFood,
AteAndGotSick,TotalAte,AteAttackRate,
NotAteAndGotSick,TotalNotAte,NotAteAttackRate,
ROUND(AteAttackRate/CAST(NotAteAttackRate AS FLOAT),2) RelativeRisk
FROM qryFoodInCases
LEFT JOIN qryNotAteAttackRate QA
ON qryFoodInCases.fldFood=QA.fldFood
LEFT JOIN qryAteAttackRate QN
ON qryFoodInCases.fldFood=QN.fldFood
GROUP BY qryFoodInCases.fldFood
ORDER BY RelativeRisk Desc
These are 2 of the sub views. There are a few more:
CREATE VIEW `qryAteAttackRate`
AS SELECT qryFoodInCases.fldCaseID,qryFoodInCases.fldFood,
COALESCE(qryAteAndGotSick.AteAndGotSick,0) AteAndGotSick,
qryFoodInCases.fldFoodFrequency TotalAte,
100*COALESCE(qryAteAndGotSick.AteAndGotSick,0)/
qryFoodInCases.fldFoodFrequency AteAttackRate
FROM qryFoodInCases
LEFT JOIN qryAteAndGotSick
ON qryFoodInCases.fldFood=qryAteAndGotSick.fldFood
GROUP BY qryFoodInCases.fldFood
CREATE VIEW `qryFoodInCases`
AS SELECT tblCases.fldCaseID,fldfood,
COUNT(tblFoodHistory.fldFoodID) AS fldFoodFrequency
FROM tblFood
INNER JOIN tblFoodHistory
ON tblFoodHistory.fldFoodID=tblFood.fldFoodID)
INNER JOIN tblMealHistory
ON tblFoodHistory.fldMealID=tblMealHistory.fldMealHistoryID)
INNER JOIN tblInterviews
ON tblInterviews.fldInterviewID=tblMealHistory.fldInterviewID)
INNER JOIN tblCases
ON tblCases.fldCaseID=tblInterviews.fldCaseID
GROUP BY tblCases.fldCaseID,tblFood.fldFood
I want to query the main view for each fldCaseID. Problem is, the WHERE condition when querying the main view does not apply to the subviews.
Other than creating a long complex SQL statement, is there a way to programmatically insert a WHERE condition into the sub views?
Aucun commentaire:
Enregistrer un commentaire