# Help in writing a POSTGRESQL

**URL:** <https://forum.freecodecamp.org/t/help-in-writing-a-postgresql/231787>\
**Category:** General\
**Created:** [October 5, 2018, 1:13pm UTC](https://forum.freecodecamp.org/t/help-in-writing-a-postgresql/231787 "2018-10-05T13:13:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nad2386](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@nad2386](https://forum.freecodecamp.org/u/nad2386)\
**Post date:** [October 5, 2018, 1:13pm UTC](https://forum.freecodecamp.org/t/help-in-writing-a-postgresql/231787/1 "2018-10-05T13:13:02Z")

</div>

Task  
Bucket 1- Value of inventory in 1st aging bucket as defined in aged inventory parameters. Typically 0-3 months. _Decimal (14.2)_

The bucket is defined as “Date of last demand”. So you will have to build a query that sum’s current on-hand inventory values based on the date of the last sale. you can get that by using select item\_id, Max(date\_of\_dmd ) from d\_demand\_transaction group by item\_id. So bucket 1 is sum of inventory value where max date is \< today – 90 days)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:09pm UTC](https://forum.freecodecamp.org/t/help-in-writing-a-postgresql/231787/2 "2021-01-17T20:09:53Z")

</div>


