MS Access max date and recent date and their respective qty -


looking maxdate, recent date , interval between. of maxdate , recent, need quantities each can find interval

table "tblitem_inventorycount" structure follows:

item_no count date qty

001 08/29/2015 12

001 08/15/2015 17

001 07/15/2015 19

item no 001

max(countdate) 08/29/2015

priorcountdate 08/15/2015

interval days (maxdate-recentdate) 14

maxdate quantity 12

priorcountdate quantity 17

interval qty (17-12) 5

currently using query find last 2 count dates each item_no

select tblitem_inventorycount.item_no, tblitem_inventorycount.quantity, tblitem_inventorycount.countdate tblitem_inventorycount (((tblitem_inventorycount.countdate)>=nthingroup([tblitem_inventorycount].[item_no],2))) order tblitem_inventorycount.item_no, tblitem_inventorycount.countdate desc; 

then using second query calculate data:

select qrylast2_inventorycount_transactions.item_no,      qrylast2_inventorycount_transactions.countdate, (select max([countdate]) [qrylast2_inventorycount_transactions] [old orders] [old orders].[countdate] < [qrylast2_inventorycount_transactions].[countdate] , [old orders].[item_no] = [qrylast2_inventorycount_transactions].[item_no]) priorcountdate, [countdate]-[priorcountdate] daysinterval, qrylast2_inventorycount_transactions.quantity, (select last([quantity]) [qrylast2_inventorycount_transactions] [oldcount] [oldcount].[quantity] < [qrylast2_inventorycount_transactions].[quantity] , [oldcount].[item_no] = [qrylast2_inventorycount_transactions].[item_no]) priorquantity, [quantity]-[priorquantity] quantityinterval, [quantityinterval]*30/[daysinterval] [usage] qrylast2_inventorycount_transactions group qrylast2_inventorycount_transactions.item_no, qrylast2_inventorycount_transactions.countdate, qrylast2_inventorycount_transactions.quantity order qrylast2_inventorycount_transactions.item_no, qrylast2_inventorycount_transactions.countdate desc; 

i not getting results need. query returns 2 record lines each item along max or last countdate, previous countdate, intervaldays, qty, last qty, , interval.

i need max or last countdate , qty count , prior countdate , qty count.

any appreciated.

try :

 select     tab.item_no,     tab.max_date,     tab.priorcountdate,     datediff ("d", tab.max_date, tab.priorcountdate) intervaldays,    tab.maxdateqty,    tab.priorcountdateqty,    ( tab.maxdateqty-tab.priorcountdateqty) intervalqty,        ( select            temp1.item_no item_no,            temp1.m max_date,            (select max(count_date) tblitem_inventorycount count_date <> temp1.m ) priorcountdate,           temp1.q maxdateqty,           (select max(qty) tblitem_inventorycount qty <> temp1.q) priorcountdateqty,                ( select item_no i, qty q, max(count_date) m          group item_no, qty ) temp1         inner join            tblitem_inventorycount temp2            on            temp1.item_no = temp2.item_no      )      tab  ; 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -