Button [2.1.1 - List of roses]
Display all the details of the plants in the Rose category in the tblPlants table - NSC Information Technology - Question 2 - 2019 - Paper 1
Question 2
Button [2.1.1 - List of roses]
Display all the details of the plants in the Rose category in the tblPlants table.
Example of output of the first five records: ... show full transcript
Worked Solution & Example Answer:Button [2.1.1 - List of roses]
Display all the details of the plants in the Rose category in the tblPlants table - NSC Information Technology - Question 2 - 2019 - Paper 1
Step 1
Button [2.1.1 - List of roses]
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To display all details of the plants in the Rose category from the tblPlants table, use the following SQL query:
SELECT * FROM tblPlants WHERE Category = 'Rose';
This query selects all fields from the tblPlants table where the Category is 'Rose'.
Step 2
Button [2.1.2 - Pink roses and flowers]
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To retrieve the PlantCode, Category, Colour, and SizeOfPot fields for all plants in the Flower and Rose categories, use:
SELECT PlantCode, Category, Colour, SizeOfPot FROM tblPlants WHERE (Category = 'ROSE' OR Category = 'FLOWER') AND Colour LIKE '%Pink%';
This ensures that we get records from both categories that include the colour Pink.
Step 3
Button [2.1.3 - Average price per category]
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To calculate the average price of plants per category, the following SQL can be used:
SELECT Category, FORMAT(AVG(Price), 'Currency') AS AveragePrice FROM tblPlants GROUP BY Category;
This retrieves the average price formatted as currency for each category.
Step 4
Button [2.1.4 - Display information for invoice number F2]
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To display information for invoice number F2, execute:
SELECT InvoiceNum, Description, NumberOrdered FROM tblPlants, tblOrders WHERE tblOrders.PlantCode = tblPlants.PlantCode AND InvoiceNum = 'F2';
This SQL query joins both tables based on the PlantCode and filters by InvoiceNum.
Step 5
Button [2.1.5 - Update items delivered]
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To update the NumberDelivered field to match the NumberOrdered for a specific item, use:
UPDATE tblOrders SET NumberDelivered = NumberOrdered WHERE ItemNum = 'QuotedStr(ItemNum)';
This SQL command correctly updates the records according to the provided ItemNum.