Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A MySQL query that gets the list of products sold and the total sales amount for each category could be: a select distinct a.CategoryID, a.CategoryName,

A MySQL query that gets the list of products sold and the total sales amount for each category could be:

a

select

distinct a.CategoryID,

a.CategoryName,

b.ProductName,

sum(c.ExtendedPrice) as ProductSales

from

Categories a

inner join

Products b

on

a.CategoryID = b.CategoryID

inner join

(

select

distinct y.OrderID,

y.ProductID,

x.ProductName,

y.UnitPrice,

y.Quantity,

y.Discount,

round(y.UnitPrice * y.Quantity * 1 - y.Discount, 2) as ExtendedPrice

from

Products x

inner join

Order_Details y

on

x.ProductID = y.ProductID

order by

y.OrderID

b

select

distinct a.CategoryID,

a.CategoryName,

b.ProductName,

sum(c.ExtendedPrice) as ProductSales

from

Categories a

inner join

Products b

on

a.CategoryID = b.CategoryID

inner join

(

select

distinct y.OrderID,

y.ProductID,

x.ProductName,

y.UnitPrice,

y.Quantity,

y.Discount,

round(y.UnitPrice * y.Quantity * (1 - y.Discount), 2) as ExtendedPrice

from

Products x

inner join

Order_Details y

on

x.ProductID = y.ProductID

order by

y.OrderID

) c

on

c.ProductID = b.ProductID

inner join

Orders d

on

d.OrderID = c.OrderID

where

d.OrderDate between date('1997/1/1') and date('1997/12/31')

group by

a.CategoryID

, a.CategoryName

, b.ProductName

order by

a.CategoryName

, b.ProductName

, ProductSales;

c

select

a.CategoryID,

a.CategoryName,

b.ProductName,

sum(c.ExtendedPrice) as ProductSales

from

Categories a

inner join

Products b

on

a.CategoryID = b.CategoryID

inner join

(

select

distinct y.OrderID,

y.ProductID,

x.ProductName,

y.UnitPrice,

y.Quantity,

y.Discount,

round(y.UnitPrice * y.Quantity * (1 - y.Discount), 2) as ExtendedPrice

from

Products x

inner join

Order_Details y

on

x.ProductID = y.ProductID

order by

y.OrderID

) c

on

c.ProductID = b.ProductID

inner join

Orders d

on

d.OrderID = c.OrderID

where

d.OrderDate between date('1997/1/1') and date('1997/12/31')

group by

a.CategoryID

, a.CategoryName

, b.ProductName

order by

a.CategoryName

, b.ProductName

, ProductSales;

d

select

distinct a.CategoryID,

a.CategoryName,

b.ProductName,

sum(c.ExtendedPrice) as ProductSales

from

Categories a

inner join

Products b

on

a.CategoryID = b.CategoryID

inner join

(

select

distinct y.OrderID,

y.ProductID,

x.ProductName,

y.UnitPrice,

y.Quantity,

y.Discount,

round(y.UnitPrice * y.Quantity * (1 - y.Discount), 2) as ExtendedPrice

from

Products x

inner join

Order_Details y

on

x.ProductID = y.ProductID

order by

y.OrderID

)

on

c.ProductID = b.ProductID

inner join

Orders d

on

d.OrderID = c.OrderID

where

d.OrderDate between date('1997/1/1') and date('1997/12/31')

group by

a.CategoryID

, a.CategoryName

, b.ProductName

order by

a.CategoryName

, b.ProductName

, ProductSales;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago