I am having problems working out a sum in a query. It requires a CAST I'm sure.
The query - I want to find out how much each parents total number of activities costs. The price of each activity is $5.50, therefore someone with 4 activities would be $22 total.
It requires 3 columns which are for Parent Name, total activities, and total cost.
I can't work out the total cost for each parent's total activities...
Please help
code
SELECT CONCAT_WS(" ", P.parent_title, P.parent_fname, P.parent_sname) AS Parent,
COUNT(A.activity_name) AS Total_Activities
FROM Activity A, Child C, Parent P, ChildActivity
WHERE P.parent_id = C.parent_id
AND C.child_id = ChildActivity.child_id
AND A.activity_id = ChildActivity.activity_id
GROUP BY Parent
ORDER BY P.parent_sname, P.parent_fname
Results example: (actually lists 11 people)
*Parent* *Total Activities*
MR James Dean 4
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…