我正在尝试总结按日期分组的数量(PartNum),Lot& 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`
但没有快乐。
我知道这很简单,但我看不到它。