Goal: I'm trying to store the tables results of a query as a variable in a function. I'd like to be able to do more things in this procedure referencing these tables.
I've got a scaffold function below:
DELIMITER $$
CREATE FUNCTION getRatio(treatmentA INT, treatmentB INT)
RETURNS FLOAT
BEGIN
DECLARE answer FLOAT;
DECLARE countA, countB, countABIntersection;
# Store patients of treatment A
SELECT DISTINCT patient
INTO **Variable**
FROM Treatment
WHERE TreatmentID = treatmentA;
# Store patients of treatment B
SELECT DISTINCT patient
INTO **Variable**
FROM Treatment
WHERE TreatmentID = treatmentB;
# Get Intersection of treatment B
Set answer = count(TreatmentA) * count(TreatmentB) * count(IntersectionTreatmentAB)
RETURN answer;
END $$
DELIMITER ;
If anyone can help, it would be greatly appreciated. Thanks in advance.