如何在firebird select子句中为每个超过25的数量创建一行

时间:2014-09-08 22:24:44

标签: firebird firebird2.5

我使用的是Firebird 2.5数据库,我需要读取一个表,并根据数量在select语句中创建其他数据记录。例如,如果数量的值为10,我想创建一个数量为10的记录。如果数量的值为30,我需要创建两个记录。一个数量为25,另一个数量为5.我总是希望将数量除以25,并为每个数量25和一个剩余数量创建记录。

这是当前的sql。我如何修改它以创建其他记录?

SELECT 
trackinginfo.info AS ID,
IIF (pickitem.qty*(COALESCE(uomconversion.multiply,1)/COALESCE(uomconversion.factor,1)) > 4,        ROUND(pickitem.qty*  (COALESCE(uomconversion.multiply,1)/COALESCE(uomconversion.factor,1)),2),ROUND(pickitem.qty*(COALESCE(uomconversion.multiply,1)/COALESCE(uomconversion.factor,1)),4)) AS "Quantity Kg",
part.num||'-'||part.description as Part,
PICK.NUM AS "order"
FROM PICKITEM 
INNER JOIN PART ON PICKITEM.PARTID = PART.ID 
INNER JOIN WO ON PICKITEM.ORDERID = WO.ID 
INNER JOIN PICK ON PICKITEM.PICKID = PICK.ID 
INNER JOIN UOM ON PICKITEM.UOMID = UOM.ID
LEFT join trackinginfo on trackinginfo.recordid = pickitem.id and trackinginfo.tableid =   -1515431424 and trackinginfo.parttrackingid = 5
left join uomconversion on uomconversion.touomid = (select id from uom where code = 'kg') and   uomconversion.fromuomid = pickitem.uomid
WHERE PICKITEM.STATUSID=30 
AND UOM.ID IN (8,14) 
AND PICKITEM.ORDERTYPEID=30
ORDER BY PICK.NUM, "Quantity Kg", trackinginfo.info 

0 个答案:

没有答案