Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8036715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:42:37+00:00 2026-06-05T02:42:37+00:00

I have four tables like this: mysql> describe courses; +—————–+————-+——+—–+———+—————-+ | Field | Type

  • 0

I have four tables like this:

mysql> describe courses;
+-----------------+-------------+------+-----+---------+----------------+
| Field           | Type        | Null | Key | Default | Extra          |
+-----------------+-------------+------+-----+---------+----------------+
| course_id       | int(11)     | NO   | PRI | NULL    | auto_increment |
| course_name     | varchar(75) | YES  |     | NULL    |                |
| course_price_id | int(11)     | YES  | MUL | NULL    |                |
+-----------------+-------------+------+-----+---------+----------------+

mysql> describe pricegroups;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| price_id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| price_name  | varchar(255) | YES  |     | NULL    |                |
| price_value | int(11)      | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+

mysql> describe courseplans;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| plan_id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| plan_name  | varchar(255) | YES  |     | NULL    |                |
| plan_time  | int(11)      | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

mysql> describe course_to_plan;
+-----------+---------+------+-----+---------+-------+
| Field     | Type    | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+-------+
| course_id | int(11) | NO   | PRI | NULL    |       |
| plan_id   | int(11) | NO   | PRI | NULL    |       |
+-----------+---------+------+-----+---------+-------+

Let me try to explain what I have and what I would like to do…

All my courses (course_id) has different steps (plan_id) wich has a value of 1 or more days (plan_time).

A course has one or more steps (course_to_plan)

A course is connected to a pricegroup (price_id).

I would like to query my MySQL database and get an output off:
The course_name, the plan_id‘s it has, and based on the value of price_id together with the value in the plan_time get a result who looks something like this:

+------------+--------------+------------+---------+
| course_name| pricegroup   | plan_time  | RESULT  | 
+------------+--------------+------------+---------+
| Math       | Expensive    | 7          | 3500    |
+------------+--------------+------------+---------+

I hope you understand me…
Is it even possible with the structure I have or should I “rebuild-and-redo-correct” something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:42:39+00:00Added an answer on June 5, 2026 at 2:42 am
    SELECT c.course_name, p.price_name, SUM(cp.plan_time), SUM(cp.plan_time * p.price_value)
    FROM courses c
        INNER JOIN pricegroups p        ON p.price_id = c.course_price_id
        INNER JOIN course_to_plan cpl   ON cpl.course_id = c.course_id
        INNER JOIN courseplans cp       ON cp.plan_id = cpl.plan_id
    GROUP BY c.course_name, p.price_name
    

    Please note that it seems to me that your implementation might be erroneous. The way you want the data makes me think that you could be happier with a plan having a price, so you don’t apply the same price for a plan which is “expensive” AND another plan which is “cheap”, which is what you are doing at the moment. But I don’t really know, this is intuitive 🙂

    Thanks for accepting the answer, regards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have four tables like below in sql server 2008 : TABLE 1 ->
I have a MySQL query like this SELECT id,seq,text FROM table ORDER BY seq
I have four tables: days CREATE TABLE days ( day text priamry key );
I have four tables, Shops Sales Batches Products and I would like to extract
I have four tables, each looks like ID Value 1 23.43 2 34.23 1
I have four entities that I would like to translate into database tables via
I have four tables: Users PrivilegeGroups rdPrivileges LinkPrivilege ----------- ---------------- --------------- --------------- userId(pk) privilegeGroupId(pk)
I have four tables: SalesPerson ( personId int ,PersonName nvarchar(20) ..) personAndDistrict ( autoId
I have four tables in database. person(Perid ,firstname , lastname , gender) Research (Resid
I have four tables in my database( notes , expense , category and items

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.