Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sales by product category


sales by product category

Author
Message
josephmoka
josephmoka
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 27
Return the number of sales by product category where the average recommended price is
R10 or more greater than the average sales price.
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16455 Visits: 13207
Is this a homework question?

Also, please provide table DDLs and sample data please.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
josephmoka
josephmoka
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 27
yes it is i only have

three table

tblCustomer

customerID
Firstname
lastname
city
state
postCode


tblSales

SalesID
productID
customerID
salePrice
saleDate

tblProducts

productID
parentProductID
productName
recommendedPRice
catercory
alekya
alekya
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 178
Create Script
CREATE TABLE [dbo].[Sales](
[Department] [nvarchar](50) NULL,
[price] [int] NULL
)

Sample data taken

Department price
A 10
B 5
A 15
A 3
B 15
C 11
D 3
D 2


SELECT DEPARTMENT,PRICE FROM [DBO].[SALES] A
WHERE DEPARTMENT
IN(
SELECT DEPARTMENT FROM [DBO].[SALES] B WHERE
A.DEPARTMENT =B.DEPARTMENT
GROUP BY DEPARTMENT Having AVG(B.PRICE) >=10
)
Dhruvesh Shah
Dhruvesh Shah
SSChasing Mays
SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)

Group: General Forum Members
Points: 635 Visits: 237
Following query will get you result for

Return the number of sales by product category where the average recommended price is
R10 or more



SELECT COUNT(S.SalesID)
FROM tblSales AS s
INNER JOIN tblProducts AS P ON
S.productID = P.productID
GROUP BY p.catercory
HAVING AVG(P.recommendedPRice) >= 10



If you want to also check for recommended price greater than the average sales price you have to add following addtional checks

OR AVG(P.recommendedPRice) > AVG(S.salePrice)


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search