in Education by
The tables are: 1) Producers: id, name 2) Products: id, name, price, category_id, producer_id 3) Customers: id, name, surname, age, country_id 4) Customer_orders: id, customer_id, product_id, quantity, discount, order_date I need to find the prodcuer, who's income was the highest, in other words: find a producer for which the sum of all prodcut price * quantity - discount is the highest. I suppose, that I should join table customer_orders with product_id column on products, and products with producers table on column id and then calculate the appropriate income for all producers and then find the maximum value. The problem is, how to write in in MySql. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can start with something like this: SELECT SUM(price - discount) income, producers.name name FROM customer_orders LEFT JOIN products ON customer_orders.product_id = products.id LEFT JOIN producers ON producers.id = products.producer_id GROUP BY producer_id I'm not sure if that will work exactly how I typed it but it should be a starting point. Here are some helpful links: Left Joins Sum Function Please note: I'm currently working on a server where the tables are structured like this, and it's super slow and a pain to get anything done. I'd encourage you to consider at least adding the total order about and the producer_id to the customer_orders table to make it a lot easier.

Related questions

0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Im trying to insert the current date and a specific time into a table this is my query INSERT INTO ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Im trying to insert the current date and a specific time into a table this is my query INSERT INTO ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Hi I have two tables here: Transcript Grade Student_number Course_number Semester Year A 8 MATH2410 Fall 07 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    Hi I have two tables here: Transcript Grade Student_number Course_number Semester Year A 8 MATH2410 Fall 07 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I got that table : id, user_a, user_b, score 1, 3, 7, 19 2, 8, 3, 20 3, 3, ... JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I got that table : id, user_a, user_b, score 1, 3, 7, 19 2, 8, 3, 20 3, 3, ... JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I have 2 entity: /** * @ORM\Entity * @ORM\Table(name="users") */ class User { /** * ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    tableone a |b| c -------- a1 | |c1 a2 | |c2 a3 | |c3 tabletwo a | b ----- ... JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What are different tables and default database present in MySQL?...
asked Nov 22, 2020 in Technology by JackTerrance
0 votes
    Can anybody let me know the query to find all the tables that has a date columns on it. Thanks ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    I have multiple set of data to insert at once, say 4 rows. My table has three columns: Person, Id and ... a single SQL statement? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
...