以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  找出每个物品最后一次记录  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=176488)

--  作者:nxqtxwz
--  发布时间:2022/4/14 20:13:00
--  找出每个物品最后一次记录
"防控物资储备"是个流水账,有很多条记录,有的物品名是相同的,但入库的日期不同。
我想找出每个物品最后一次的记录。怎么写呢?


Dim Customers As List(Of String)
Customers = DataTables("防控物资储备").GetValues("物品名称","","日期 Desc")
For Each Customer As String In Customers
    Output.Show(Customer)
Next


--  作者:有点蓝
--  发布时间:2022/4/14 21:04:00
--  
这种只能使用sql,类似:http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=171529&skin=0
--  作者:nxqtxwz
--  发布时间:2022/4/17 16:52:00
--  
在命令窗口运行出错
S elect a.物品名称,a.库存 fro m {防控物资储备} As a inner join(Sel ect 物品名称,max(日期) As 日期 fro m {防控物资储备} group by 物品名称) As b on a.物品名称 = b.物品名称 And a.日期=b.日期

--  作者:有点蓝
--  发布时间:2022/4/17 20:34:00
--  
http://www.foxtable.com/webhelp/topics/1484.htm

如果不是SqlServer

S elect a.物品名称,a.库存 fro m {防控物资储备} As a inner join(Sel ect 物品名称,max(日期) As 日期 fro m {防控物资储备} group by 物品名称) As b on a.物品名称 = b.物品名称 where a.日期=b.日期

--  作者:nxqtxwz
--  发布时间:2022/4/18 8:14:00
--  
老师,是SqlServer

图片点击可在新窗口打开查看
--  作者:有点蓝
--  发布时间:2022/4/18 8:37:00
--  
看4楼帮助链接,到sql窗口执行
--  作者:kylin
--  发布时间:2022/4/18 13:58:00
--  
Dim Customers As List(Of String)
Customers = DataTables("防控物资储备").GetValues("物品名称")
For Each Customer As String In Customers
Dim fdr = DataTables("防控物资储备").Find("物品名称 = \'"& Customer &"\'","日期 Desc")
if fdr isnot nothing
    Output.Show(Customer)
    Output.Show(fdr!日期)
end if
Next
[此贴子已经被作者于2022/4/18 13:58:02编辑过]

--  作者:nxqtxwz
--  发布时间:2022/4/19 7:55:00
--  
请问老师,下面的代码不能写在菜单的按钮里吗?如果能写到菜单按钮事件中,怎么改 呢?
Se lect a.物品名称,a.规格型号,a.单位,a.日期,a.库存,a.是否分发完 fr om {防控物资储备} As a inner join(Se lect 物品名称,max(日期) As 日期 fr om {防控物资储备} group by 物品名称) As b on a.物品名称 = b.物品名称 where a.日期=b.日期

--  作者:有点蓝
--  发布时间:2022/4/19 8:35:00
--  
使用SQLCommand:http://www.foxtable.com/webhelp/topics/0696.htm
--  作者:kennypalm
--  发布时间:2022/4/19 17:46:00
--  
你记录一下成单的日期时间 用sql order by,  例如 selec t top 1 item_date, * from item order by updated_on desc 其实也能做到你的要求