Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

MySQL - What's the total cost in price for each person's total number of courses?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As this is homework, I can not give you the answer right away. Think it this way: You can apply math to column values :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...