Question

In: Computer Science

We continue from the two tables in lab 3 part 2, and practice with functions and...

We continue from the two tables in lab 3 part 2, and practice with functions and the GROUP BY statement. The data in each table should be as below

Table Product:

PROD_ID

PROD_NAME

PROD_PRICE

PROD_VENDOR

1101

Table

100

2

1102

Chair

80

3

1103

Armchair

90

2

1104

Nightstand

110

1

1105

Bed

200

3

1106

Dresser

150

3

1107

Daybed

190

2

1108

Ash Table

120

2

1109

Cherry Table

130

2

1110

Table - High

100

2

1111

Office Chair

110

3

Table Vendor:

VEND_ID

VEND_NAME

VEND_ST

1

Green Way Inc

GA

2

Forrest LLC

NC

3

AmeriMart

NC

Please write the SQL script and provide screenshots of results for these below queries. Please include the SQL in text format, and all screenshots in one single document.

  1. Find the average prices by vendors (please include vendor names in the query result)
  2. Find the average prices by states

Help:

I do it the following way, but it gives me an error " NO ROWS SELECTED." Also, I had to  group by V.VEND_NAME, P.PROD_VENDOR, otherwise I'll  get an error message. Please help me figure this out. Same for # 5. Thanks.

select P.PROD_VENDOR, V.VEND_NAME, avg(P.PROD_PRICE) as AVG_PRICE from

PRODUCT P join Vendor V on P.PROD_VENDOR = V.VEND_ID group by V.VEND_NAME, P.PROD_VENDOR;

Solutions

Expert Solution

Hi,

There should be no such need to group the tables by both the fields, vendor name as well as vendor Id from product table. I would recommend you to check the underlying schema of your tables.

I didn't encounter any such error, below are my queries-

mysql> Select vendor.VEND_NAME, Avg(PROD_PRICE) from vendor, product
-> where vendor.VEND_ID = product.PROD_VENDOR
-> group by vendor.VEND_ID;
+---------------+-----------------+
| VEND_NAME | Avg(PROD_PRICE) |
+---------------+-----------------+
| Forrest LLC | 121.6667 |
| AmeriMart | 135.0000 |
| Green Way Inc | 110.0000 |
+---------------+-----------------+
3 rows in set (0.00 sec)

mysql> Select vendor.VEND_ST, Avg(PROD_PRICE) from vendor, product
-> where vendor.VEND_ID = product.PROD_VENDOR
-> group by VEND_ST;
+---------+-----------------+
| VEND_ST | Avg(PROD_PRICE) |
+---------+-----------------+
| NC | 127.0000 |
| GA | 110.0000 |
+---------+-----------------+
2 rows in set (0.00 sec)

Therer might be slight variations in our queries due to the cases of table names and field names (upper case/lower case) . Kindly match up the logic of your query with the ones above.

If that still doesn't work out, kindly share your schema and the error screenshot. Will be happy to help you.. thanks!


Related Solutions

We continue from the two tables in lab 3 part 2, and practice with functions and...
We continue from the two tables in lab 3 part 2, and practice with functions and the GROUP BY statement. The data in each table should be as below Table Product: PROD_ID PROD_NAME PROD_PRICE PROD_VENDOR 1101 Table 100 2 1102 Chair 80 3 1103 Armchair 90 2 1104 Nightstand 110 1 1105 Bed 200 3 1106 Dresser 150 3 1107 Daybed 190 2 1108 Ash Table 120 2 1109 Cherry Table 130 2 1110 Table - High 100 2 1111...
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and...
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and use a function named highest() that takes three inputs and returns the highest number. After you have got it working, try calling the function with inputs ‘hat’, ‘cat’, ‘rat’.
Lab 1 – Databases, Schemas, and Basic Tables For this lab we will be creating a...
Lab 1 – Databases, Schemas, and Basic Tables For this lab we will be creating a small Student Loan Database. Make sure to open your screenshot word document. Include the required screenshots of your code in the document. Database: Create a new database: StudentLoan_LastName. Schemas: Create the following schemas. Make sure to screenshot and run your code: 1. Student 2. Guarantor 3. Institution 4. Activity 5. Loan 6. Lender Tables: First complete the word document for designing the tables like...
17.1 Lab Lesson 10 (Part 1 of 2) Part of lab lesson 10 There are two...
17.1 Lab Lesson 10 (Part 1 of 2) Part of lab lesson 10 There are two parts to lab lesson 10. The entire lab will be worth 100 points. Bonus points for lab lesson 10 There are also 10 bonus points. To earn the bonus points you have to complete the Participation Activities and Challenge Activities for zyBooks/zyLabs unit 16 (Gaddis Chapter 7). These have to be completed by the due date for lab lesson 10. For example, if you...
In this lab we will write 3 functions: GenData: This function will take an integer parameter...
In this lab we will write 3 functions: GenData: This function will take an integer parameter and return a vector with that many random integers generated in the range of 0 and 100 (rand()%101). Seed the random number generator with 22. Mean(): This function will take a vector and return the mean. Variance(): This function will take a vector and return the population variance, as: [Sum for values[( x_i - Mean )^2]] / (number of items) In Main: Use GenData...
Language: C++ 3 Campus Travel Game This lab will practice using loops. We will construct a...
Language: C++ 3 Campus Travel Game This lab will practice using loops. We will construct a short computer game. Please look at the Test Cases for exact wording. For your game, the player’s goal is to reach campus exactly. The player starts 14 miles away and has up to 4 turns to reach campus. At each turn the play can ride either use a Bus, a Subway, or a Jetpack: Riding a Bus moves the player forward 2 miles each...
2.       The next two tables are summaries from a neighborhood survey. Use the information in the tables...
2.       The next two tables are summaries from a neighborhood survey. Use the information in the tables to summarize the results of the survey. Which of the neighborhoods would you consider the lowest income neighborhood? Explain your answer? TABLE 2 CROWN HEIGHTS,   EAST NEW YORK PROSPECT HEIGHTS / FLATBUSH BED-STUY / BUSHWICK INCOME Count % Count % Count % LESS THAN $15,000 45 19.7% 5 7.8% 11 8.3% $15,000 - $24,999 69 30.1% 25 39.1% 38 28.6% $25,000 - $34,999 64...
Construct a graph from Tables 2 and 3 on a computer program such as Microsoft Excel®. Send your graph with your Post-Lab Questions to your lab instructor.
  Table 1: Hot Sauce Titration mass of hotsauce (g) 0.8 Concentration of NaOH solution used 0.1M Volume needed of NaOH to neutralize the sauce_______? pH of NaOH 12.5 Table 2: Hot Sauce pH Titration Data Trial 1 Increments of NaOH Added (mL) Total NaOH Added (mL) Hot Sauce pH 0 0 3.7 1.0 1.0 4.1 1.0 2.0 4.4 1.0 3.0 4.8 1.0 4.0 5.6 1.0 5.0 9.7 1.0 6.0 11.2 1.0 7.0 11.5 1.0 8.0 11.7 1.0 9.0 11.9...
1. Practice searching 2. Continue learning the significance of special cases! 3. Learning how to write...
1. Practice searching 2. Continue learning the significance of special cases! 3. Learning how to write test to check your implementation Things you must do: 1. There are many details in this lab. Make sure you read the whole thing carefully before writing any code and closely follow this instruction. 2. Always remember Java is case sensitive. 3. Your file names, class names, and package name must match exactly as they are specified here. Things you must not do: 1....
1. A product of two functions (exponential) 2. A quotient of two functions (logarithmic) 3. example...
1. A product of two functions (exponential) 2. A quotient of two functions (logarithmic) 3. example of a composite function 4. A sum of two functions (rational) 5. A difference of two function (rational or either trigonometric) for all the functuons you come up w please give the domin range x and y int ans local max and min.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT