KnowledgeBoat Logo
|

Informatics Practices

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

iduservaluehashtransaction_date
1Steve900ERTYU2020-09-19
2Meesha145@345r2021-03-23
3Nimisha567#wert52020-05-06
4Pihu678%rtyu2022-07-13
5Kopal768rrt4%2021-05-15
7Palakshi534wer@32022-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.

DDL & DML

6 Likes

Answer

(i)

SELECT YEAR(MIN(transaction_date)) AS oldest_year
FROM BLOCKCHAIN;
Output
+-------------+
| oldest_year |
+-------------+
|        2020 |
+-------------+

(ii)

SELECT MONTH(MAX(transaction_date)) AS most_recent_month
FROM BLOCKCHAIN;
Output
+-------------------+
| most_recent_month |
+-------------------+
|                11 |
+-------------------+

(iii)

SELECT *
FROM BLOCKCHAIN
WHERE MONTH(transaction_date) = 5;
Output
+----+---------+-------+--------+------------------+
| 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;
Output
+-------------------------+
| total_transactions_2022 |
+-------------------------+
|                       2 |
+-------------------------+

Answered By

3 Likes


Related Questions