Advertisements
Advertisements
प्रश्न
Abhishek has created a table, named STOCK, with a set of records to maintain the data of packaged milk in his shop. After creating the table, he entered the data and the table looked as follows:
| Code | Type | Volume | Qty | Price |
| AF0.5 | F | 0.5 | 300 | 38.00 |
| MFO.5 | F | 0.5 | 250 | 36.50 |
| MT1.О | T | 1.0 | 150 | 64.00 |
| AT1.0 | T | 1.0 | 100 | 66.00 |
| PD1.0 | D | 1.0 | 50 | 52.00 |
| PT0.5 | T | 0.5 | 78 | 30.00 |
Based on the data given above, write the SQL queries for the following tasks:
- To display
Typeand the maximumPricefor eachTypeof milk. - For each record, increase the
Priceby 0.5 whereTypeis 'F'. - To display the total value of the stock (total of
QtyxPrice). - To display the details of all records where
Codestarts with'A'.
दीर्घउत्तर
Advertisements
उत्तर
SELECT Type, MAX(Price) FROM STOCK GROUP BY Type;- Why:
GROUP BYis essential here to categorise the maximums by each specificType.
- Why:
UPDATE STOCK SET Price = Price + 0.5 WHERE Type = 'F';- Why:
UPDATEIs the correct DML command for modifying existing data
- Why:
SELECT SUM(Qty * Price) FROM STOCK;- Why: SQL allows arithmetic operations inside aggregate functions like
SUM().
- Why: SQL allows arithmetic operations inside aggregate functions like
SELECT * FROM STOCK WHERE Code LIKE 'A%';- Why: The
%A wildcard is used withLIKEto match any characters following the letter 'A'.
- Why: The
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
