我从下面开始以下查询。目标是确定从仓库装运的部分托盘的数量。通过查看托盘的log.tran_qty(hu_id)并将其与uom.std_hand_qty进行匹配,可以识别出部分托盘。如果不匹配,则为部分托盘。如果将hu_id添加到SELECT子句中,我可以使此查询正常工作,但是如果这样做,则数据集非常大。无论如何,我是否需要通过log.hu_id获得SUM(log._tran_qty),而不必将hu_id添加到select子句中?希望这是有道理的...
SELECT log.end_tran_date, COUNT(DISTINCT(hu_id)) as 'Pallets'
FROM t_tran_log log
LEFT JOIN t_item_uom uom ON log.item_number = uom.item_number
and uom.wh_id=log.wh_id
WHERE log.wh_id = 'LANDAIR_C2'
and SUBSTRING(log.item_number,6,1) <> 'P'
and tran_type='341' and uom.uom = 'CA'
GROUP BY log.end_tran_date
HAVING SUM(log.tran_qty) <> AVG(uom.std_hand_qty)
ORDER BY log.end_tran_date
谢谢。