我有这行SQL代码(我正在使用MySQL Workbench)
INSERT INTO haulrecord(invoiceNumber, TruckUsed, Client, CargoType,
BeginDate, DeliveryDate, Mileage, Notes)
VALUES('203', '1857', '5', 'Batteries', '06/10/2014', '06/10/2014', '51', 'None');
我打算制作一个存储过程,但想在最高发票号后添加(下一张发票号码为203)
我将如何做到这一点?
答案 0 :(得分:0)
而不是使用VALUES
,而是使用SELECT
子句:
INSERT INTO haulrecord(invoiceNumber, TruckUsed, Client, CargoType,
BeginDate, DeliveryDate, Mileage, Notes)
SELECT MAX(invoiceNumber) + 1, '1857', '5', 'Batteries', '06/10/2014', '06/10/2014', '51', 'None' FROM haulrecord;