any computer science student of class 12th plz solve this
Answers
(i) Select avg(CostPerItem) from Lab where DateOfPurchase > '2015-01-01';
There are 4 items whose DateOfPurchase is greater than '2015-01-01'. They are Scanner, Camera, Hub and Ups. The average of their CostPerItem would therefore be (12000 + 25000 + 7000 + 70000)/4 = 28500.
(ii) Select sum(Operational) from Lab where CostPerItem > 20000;
There are 3 items whose CostPerItem is greater than 20000. They are Computer, Camera and Ups. The sum of their Operational would therefore be 7 + 3 + 4 = 14.
(iii) Select ItemName from Lab where Warranty > 2 and Quantity > 5;
There is 1 item whose Warranty is greater than 2 and Quantity is greater than 5. It is Computer. Therefore the ItemName would be Computer.
When checking for output-based SQL questions, it's important to first solve the 'Where' part of the command, since the output can only be determined as long as the conditions are fulfilled. Once you have an outline of the items that are to be considered, you can solve the 'Select' part of the command.
- Avg and Sum are examples of aggregate functions [otherwise known as multiple-row functions].
- Avg returns the average of the selected column.
- Sum returns the total value of the selected column.
Answer:
i) 28500.000
ii)15
iii) Computer
Explanation:
i) avg(column_name) selects all the average of costs where date was after 01-01-2015
ii) sum(column_name) returns sum where cost was >20000
iii) Item names where warrant > 2 and quantity > 5;