Topic awaiting preservation: MySQL sum() help |
|
---|---|
Author | Thread |
Lunatic (VI) Inmate From: under the bed |
posted 07-02-2009 20:17
Good afternoon. Having a little trouble with a query I am running. code: select week(Schedule.del_date) as week_num, sum(SKU.sku_ctn) as ctns_total, sum(SKU.sku_vol) as vol_total, count(distinct SKU.sku_num) as sku_total, count(distinct PO.po_num) as po_total, count(distinct Vend.vnd_name) as vnd_total, count(distinct Bill.hbl_num) as hbl_total, count(distinct Container.cnt_id) as cnt_total from Schedule left join Container on Container.cnt_id = Schedule.cnt_id left join Bill on Bill.cnt_id = Container.cnt_id left join Vend on Vend.cnt_id = Bill.cnt_id left join PO on PO.cnt_id = Vend.cnt_id left join SKU on SKU.cnt_id = PO.cnt_id where Container.sts_id = 4 group by week_num order by week_num asc
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 07-02-2009 21:20
yeah. your count (distinct sku.sku_num...) hides a cartesian product from you.,that your sums show. |
Lunatic (VI) Inmate From: under the bed |
posted 07-03-2009 15:42
Ok, it took me a while, and some further reading, to understand what you are saying, and why there is a cartesian product... |