单号ID 销售订单
1 T05209/TM-655-K/550PCS
1 T05209/TM-655-K/550PCS
4 T07071/TM-655-K/550PCS
4 T07071/TM-655-K/550PCS
5 T04001A/TM-162G8-K/500PCS
6 T05003/TM-820K9-B/201PCS
6 T05003/TM-820K9-B/201PCS
6 T04142/TM-820K9-B/401PCS
6 P-04142/TM-820K9-B/1PCS
查询结果
单号ID 销售订单 序号(查询生成)
1 T05209/TM-655-K/550PCS 1
4 T07071/TM-655-K/550PCS 1
5 T04001A/TM-162G8-K/500PCS 1
6 T05003/TM-820K9-B/201PCS 1
6 T04142/TM-820K9-B/401PCS 2
6 P-04142/TM-820K9-B/1PCS 3
个数据组合,后再生成自动序号,因销售订单是TEXT。所以用不了以下VBA
SELECT a.单号ID, a.销售订单, (select count(*) from S排产指令单明细 as b where b.单号ID=a.单号ID and b.销售订单<=a.销售订单) AS 序号
FROM S排产指令单明细 AS a
GROUP BY a.单号ID, a.销售订单;