我正在尝试对按日期、批次和 PartNum 分组的构建数量(PartNum)求和。
Date PartNum Lot Qty
e.g. 2/15/13 1003 56 21
2/15/13 1007 23 12
SELECT
`product_trans`.`PtID` AS `ID`,
`product_trans`.`PtLot` AS `Lot`,
`product_trans`.`PtRole` AS `Role`,
`product_trans`.`PtPosted` AS `Posted`,
`product_trans`.`PtStamp` AS `Stamped`,
`product_trans`.`PtLine` AS `Line`,
sum(`product_trans`.`PtQty`) AS `Qty`,
`product_trans`.`PtPart` AS `Part`,
`product_trans`.`PtPartNum` AS `PartNum`
FROM
`product_trans`
GROUP BY
`product_trans`.`PtStamp`,
`product_trans`.`PtPartNum`,
`product_trans`.`PtLot`
ORDER BY
`product_trans`.`PtStamp`,
`product_trans`.`PtPartNum`
问题是 PtStamp 是一个日期时间字段。我需要它按日期分组,而不是日期时间。
我试过这个:
GROUP BY
CURDATE(`product_trans`.`PtStamp`),
`product_trans`.`PtPartNum`,
`product_trans`.`PtLot`
但没有快乐。
我知道这很简单,但我看不到。