//SQL// run the script: create schema prod_db; set search_path to prod_db; CREATE TABLE product_groups ( group_id serial

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

//SQL// run the script: create schema prod_db; set search_path to prod_db; CREATE TABLE product_groups ( group_id serial

Post by answerhappygod »

//SQL//
run the script:
create schema prod_db;
set search_path to prod_db;
CREATE TABLE product_groups (
group_idserial PRIMARY KEY,
group_nameVARCHAR (255) NOT NULL
);
CREATE TABLE products (
product_idserial PRIMARY KEY,
product_nameVARCHAR (255) NOT NULL,
priceDECIMAL (11, 2),
group_idINT NOT NULL,
FOREIGNKEY (group_id) REFERENCES product_groups (group_id)
);
INSERT INTO product_groups (group_name)
VALUES
('Smartphone'),
('Laptop'),
('Tablet');
INSERT INTO products (product_name, group_id,price)
VALUES
('MicrosoftLumia', 1, 200),
('HTCOne', 1, 400),
('Nexus',1, 500),
('iPhone',1, 900),
('HPElite', 2, 1200),
('LenovoThinkpad', 2, 700),
('SonyVAIO', 2, 700),
('DellVostro', 2, 800),
('iPad',3, 700),
('KindleFire', 3, 150),
('SamsungGalaxy Tab', 3, 200);
Write a query that returns the product name, the price, productgroup name, along with the average prices of each productgroup. Order the results in ascending order by groupname. Do not rename the column for the average price.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply