This is how my database table looks like:
cattle_id | weight | weight_date |
---|---|---|
10001 | 300 KG | 01-01-2022 |
10002 | 350 KG | 01-01-2022 |
10003 | 400 KG | 01-01-2022 |
10001 | 310 KG | 15-01-2022 |
10002 | 362 KG | 15-01-2022 |
10003 | 415 KG | 15-01-2022 |
10001 | 318 KG | 30-01-2022 |
10002 | 375 KG | 30-01-2022 |
10003 | 430 KG | 30-01-2022 |
I need a query to get the result like below:
Cattle ID | Last Weight | 2nd Last Weight | 3rd Last Weight | Remarks | Last Weight Date |
---|---|---|---|---|---|
10001 | 318 KG | 310 KG | 300 KG | Not Satisfactory | 30-01-2022 |
10002 | 375 KG | 362 KG | 350 KG | Not Satisfactory | 30-01-2022 |
10003 | 430 KG | 415 KG | 400 KG | Satisfactory | 30-01-2022 |
Note: Weight measured after every 15 days & at least 1 KG growth per day is Satisfactory.
The data is inserted to database properly. I just want to retrieve data like above. How can I acheive this?