SELECT *
FROM [SELECT a.ID, a.商品全名, a.日均销售数量, a.安全存量, (select count(*) from 销售表 as b where b.日均销售数量>=a.日均销售数量) AS 销售排序
FROM 销售表 AS a]. AS c
ORDER BY c.销售排序;
Private Sub 更新_Click()
Dim sql As String
DoCmd.SetWarnings False
sql = "UPDATE 查询 SET 查询.安全存量 = 查询.日均销售数量*Val(forms!计算存量!text1)*Val(forms!计算存量!text5) "
sql = sql + "WHERE 查询.销售排序<=Val([forms]![计算存量]![text1])*DMax('销售排序','查询');"
DoCmd.RunSQL sql
sql = "UPDATE 查询 SET 查询.安全存量 = 查询.日均销售数量*Val(forms!计算存量!text2)*Val(forms!计算存量!text6) "
sql = sql + "WHERE 查询.销售排序>Val([forms]![计算存量]![text1])*DMax('销售排序','查询') and 查询.销售排序<=Val([forms]![计算存量]![text2])*DMax('销售排序','查询');"
DoCmd.RunSQL sql
sql = "UPDATE 查询 SET 查询.安全存量 = 查询.日均销售数量*Val(forms!计算存量!text3)*Val(forms!计算存量!text7) "
sql = sql + "WHERE 查询.销售排序>Val([forms]![计算存量]![text2])*DMax('销售排序','查询') and 查询.销售排序<=Val([forms]![计算存量]![text3])*DMax('销售排序','查询');"
DoCmd.RunSQL sql
sql = "UPDATE 查询 SET 查询.安全存量 = 查询.日均销售数量*Val(forms!计算存量!text4)*Val(forms!计算存量!text8) "
sql = sql + "WHERE 查询.销售排序>Val([forms]![计算存量]![text3])*DMax('销售排序','查询');"
DoCmd.RunSQL sql
End Sub