欢迎任何建议或想法,也许它无法完成......这是我的主要选择:
SELECT * From(
SELECT MODATA.CITEM, MODATA.QTREQ, MODATA.UNMSR, MODATA.CDESC, MODATA.USRSQ AS SQ, MODATA.OPRWU, SLQNTY.LLOCN, SLQNTY.LQNTY, ROW_NUMBER() OVER (PARTITION BY CITEM ORDER By CITEM) as L, MODATA.FLSTK,
MODATA.ISQTY, (QTREQ - ISQTY) as finalQty, SLQNTY.HOUSE, MOMAST.FITWH
FROM MODATA
LEFT OUTER JOIN SLQNTY ON SLQNTY.ITNBR = MODATA.CITEM
LEFT OUTER JOIN MOMAST ON MOMAST.ORDNO = MODATA.ORDNO
WHERE MODATA.ORDNO = 'M889360' AND FLSTK != 'U' AND FLSTK != 'C' AND (SLQNTY.HOUSE=MOMAST.FITWH OR HOUSE IS NULL)) AS X
这会拉出所有项目,如果一个项目的数量超过1则会计算行数,然后我这样做只会给我带来列表中的第一项
WHERE X.L = 1
ORDER BY X.SQ
我的问题是......我想在右边有另一列显示X或者1如果该项目有多行......那么我可以通过它来排序多个位置项在顶部。任何想法我都会画空白是否可以完成。理想情况下,我希望按X进行排序,然后我会将我的X.L = 1设置为仅拉动项目一次但仍有触发器显示该项目上有多个位置。
答案 0 :(得分:0)
搞定了!
SELECT * From(
SELECT MODATA.CITEM, MODATA.QTREQ, MODATA.UNMSR, MODATA.CDESC, MODATA.USRSQ AS SQ, MODATA.OPRWU, SLQNTY.LLOCN, SLQNTY.LQNTY, ROW_NUMBER() OVER (PARTITION BY CITEM ORDER By CITEM) as L, MODATA.FLSTK,
MODATA.ISQTY, (QTREQ - ISQTY) as finalQty, SLQNTY.HOUSE, MOMAST.FITWH, (SELECT COUNT(*) FROM SLQNTY WHERE SLQNTY.ITNBR = MODATA.CITEM AND SLQNTY.LQNTY != 0 AND (SLQNTY.HOUSE=MOMAST.FITWH OR HOUSE IS NULL)) AS T
FROM MODATA
LEFT OUTER JOIN SLQNTY ON SLQNTY.ITNBR = MODATA.CITEM
LEFT OUTER JOIN MOMAST ON MOMAST.ORDNO = MODATA.ORDNO
WHERE MODATA.ORDNO = 'M838860' AND FLSTK != 'U' AND FLSTK != 'C' AND (SLQNTY.HOUSE=MOMAST.FITWH OR HOUSE IS NULL)) AS X
WHERE X.L = 1
ORDER BY X.T DESC