Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can you help me to solve this:

Bring all one-off sales above 10 pieces per product to the base. To make a discount 15%.

CREATE TABLE Confectionery (
IDConfect INT IDENTITY NOT NULL PRIMARY KEY,
NameProduct  NVARCHAR(50) NOT NULL,
Category INT NOT NULL,
Quantity SMALLINT NOT NULL,
Price DECIMAL(20),
DateOfMaking DATE
);

CREATE TABLE ConfectioneryCategory (
IDConCat INT IDENTITY NOT NULL PRIMARY KEY,
CategoryName NVARCHAR(50) NOT NULL,
);

CREATE TABLE Sales (
SaleID INT IDENTITY NOT NULL,
Quantity INT NOT NULL,
DateOfSale DATE,
IDPastryChef INT NOT NULL,
IDProduct INT NOT NULL,
PRIMARY KEY(SaleID, IDProduct )
);

CREATE TABLE PastryChef (
IDPC INT IDENTITY NOT NULL PRIMARY KEY,
FirstName NVARCHAR(50),
LastName NVARCHAR(50),
ManifacturedProduct NVARCHAR(50)
);

ALTER TABLE Sales
ADD CONSTRAINT FK_Confectionery_Sales FOREIGN KEY (IDProduct)
REFERENCES Confectionery (IDConfect)
ON DELETE CASCADE
ON UPDATE CASCADE
;

ALTER TABLE Confectionery
ADD CONSTRAINT FK_Confectionery_ConfectioneryCategory FOREIGN KEY (Category)
REFERENCES ConfectioneryCategory (IDConCat)
ON DELETE CASCADE
ON UPDATE CASCADE
;

ALTER TABLE Sales
ADD CONSTRAINT FK_Sales_PastryChef FOREIGN KEY (IDPastryChef)
REFERENCES PastryChef (IDPC)
ON DELETE CASCADE
ON UPDATE CASCADE
;

INSERT INTO ConfectioneryCategory(CategoryName) 
VALUES('deep fried'),('diabetic'),('cakes'),('crakers');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Donuts', 1, 50,'0.99','2021-11-01');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Luqaimat', 1, 30 ,'4.12', '2021-11-12');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Tulumba', 1, 28 ,'1.25','2021-11-13');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Julbia', 1, 15 ,'1.15','2021-11-11');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking) 
VALUES('Peanut Butter Cookies', 2, 80,'2.99','2021-10-14');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Chocolate Keto Fat Bombs', 2, 100 ,'3.20','2021-10-05');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES(' Yogurt Ice Cream', 2, 7 ,'2.50','2021-11-02');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Pumpkin and raspberry muffins', 2, 9 ,'2.50','2021-10-17');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Garash cake', 3, 5 ,'15.00','2021-11-04');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Black Forest cake', 3, 4 ,'20.00','2021-11-11');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Red velvet', 3, 12, '1.60','2021-10-07');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Oreo cake', 3, 12, '1.80','2021-11-02');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Creem Crakers', 4, 35 ,'1.00','2021-11-12');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking) 
VALUES('Salts', 4, 64 ,'0.30','2021-10-12');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Brecel', 4, 14 ,'1.35','2021-11-15');

INSERT INTO Confectionery(NameProduct,Category,Quantity,Price,DateOfMaking ) 
VALUES('Olive crakers', 4 , 12 ,'0.99','2021-10-13');

INSERT INTO PastryChef(FirstName,LastName,ManifacturedProduct) 
VALUES('Kiril', 'Petrov', 'Brecel');

INSERT INTO PastryChef(FirstName,LastName,ManifacturedProduct) 
VALUES('Alexander', 'Dimitrov', 'Red velvet');

INSERT INTO Sales(Quantity,DateOfSale,IDPastryChef,IDProduct) 
VALUES(15, '2021-11-16', 1, 3);

INSERT INTO Sales(Quantity,DateOfSale,IDPastryChef,IDProduct) 
VALUES(24, '2021-11-16', 1,6);

INSERT INTO Sales(Quantity,DateOfSale,IDPastryChef,IDProduct) 
VALUES(4, '2021-11-12', 2,8);

INSERT INTO Sales(Quantity,DateOfSale,IDPastryChef,IDProduct) 
VALUES(0, '2021-11-12', 2,10);

INSERT INTO Sales(Quantity,DateOfSale,IDPastryChef,IDProduct) 
VALUES(10, '2021-10-05', 2,12);

INSERT INTO Sales(Quantity,DateOfSale,IDPastryChef,IDProduct) 
VALUES(16, '2021-10-05', 1,13);

INSERT INTO Sales(Quantity,DateOfSale,IDPastryChef,IDProduct) 
VALUES(4, '2021-11-27', 2,16);


What I have tried:

I don't understand how can i bring one-time sales for 10 pieces per product.
Posted
Updated 19-Nov-21 1:15am
Comments
CHill60 18-Nov-21 11:36am    
How about checking for Quantity >= 10

1 solution

Have a look at my solution to what is either your previous question or your classmate's question at How to output in SQL[^]
Change the WHERE clause on the query to limit the results to Quantity column >= 10.
That will list all of the one-time sales of 10 or more pieces per product.

The next question is going to be related to all sales per product - in which case look at solution 1 on the same link
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900