MySQL - 每个人的课程总数的总价格是多少? [英] MySQL - What's the total cost in price for each person's total number of courses?
问题描述
我在计算查询中的总和时遇到问题.我敢肯定,它需要 CAST.
I am having problems working out a sum in a query. It requires a CAST I'm sure.
查询 - 我想知道每个父母的活动总费用是多少.每项活动的价格为 5.50 美元,因此有 4 项活动的人总共需要 22 美元.
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.
它需要 3 列,分别是父名称、总活动和总成本.
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...
请帮忙
代码
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
结果示例:(实际上列出了 11 个人)
Results example: (actually lists 11 people)
*Parent* *Total Activities*
MR James Dean 4
推荐答案
因为这是作业,我不能马上给你答案.这样想:您可以将数学应用于列值:)
As this is homework, I can not give you the answer right away. Think it this way: You can apply math to column values :)
这篇关于MySQL - 每个人的课程总数的总价格是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!