CBSE Class 12 Informatics Practices
Question 34 of 40
Practice Paper — Question 1
Back to all questions 1
Question Preeti manages database in a blockchain start-up. For business purposes, she created a table named BLOCKCHAIN. Assist her by writing the following queries :
TABLE : BLOCKCHAIN
| id | user | value | hash | transaction_date |
|---|---|---|---|---|
| 1 | Steve | 900 | ERTYU | 2020-09-19 |
| 2 | Meesha | 145 | @345r | 2021-03-23 |
| 3 | Nimisha | 567 | #wert5 | 2020-05-06 |
| 4 | Pihu | 678 | %rtyu | 2022-07-13 |
| 5 | Kopal | 768 | rrt4% | 2021-05-15 |
| 7 | Palakshi | 534 | wer@3 | 2022-11-29 |
(i) Write a query to display the year of oldest transaction.
(ii) Write a query to display the month of most recent transaction.
(iii) Write a query to display all the transactions done in the month of May.
(iv) Write a query to count total number of transactions in the year 2022.
(i)
SELECT YEAR(MIN(transaction_date)) AS oldest_year
FROM BLOCKCHAIN;+-------------+
| oldest_year |
+-------------+
| 2020 |
+-------------+
(ii)
SELECT MONTH(MAX(transaction_date)) AS most_recent_month
FROM BLOCKCHAIN;+-------------------+
| most_recent_month |
+-------------------+
| 11 |
+-------------------+
(iii)
SELECT *
FROM BLOCKCHAIN
WHERE MONTH(transaction_date) = 5;+----+---------+-------+--------+------------------+
| id | user | value | hash | transaction_date |
+----+---------+-------+--------+------------------+
| 3 | Nimisha | 567 | #wert5 | 2020-05-06 |
| 5 | Kopal | 768 | rrt4% | 2021-05-15 |
+----+---------+-------+--------+------------------+
(iv)
SELECT COUNT(*) AS total_transactions_2022
FROM BLOCKCHAIN
WHERE YEAR(transaction_date) = 2022;+-------------------------+
| total_transactions_2022 |
+-------------------------+
| 2 |
+-------------------------+