hi people. i am a moron and apparently know nothing about SQL, despite what my employers may think.
i have the query below that is returning values that are sometimes 4x more than they should be. i thought i was handling for this by grouping everything. any idea what i'm doing wrong? i know i've run into this before and have just worked around it... now i'd like to know why it's happening.
feel free to mock my code and offer insight as to how to improve...
thanks
*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
i have the query below that is returning values that are sometimes 4x more than they should be. i thought i was handling for this by grouping everything. any idea what i'm doing wrong? i know i've run into this before and have just worked around it... now i'd like to know why it's happening.
Code:
select p.sub_id
, p.sub_name
, sum(pyb.amount) py_budget
, sum(cyb.amount) cy_budget
, sum(pya.amount) py_actual
, sum(cya.amount) cy_actual
, sum(aya.amount) ay_actual
, sum(cyf.amount) cy_fcst
, sum(ayf.amount) ay_fcst
from sub_project p left join drilldown_approved pyb
on (p.sub_id = pyb.sub_id and pyb.cost_budget_year = 2006
) left join drilldown_approved cyb
on (p.sub_id = cyb.sub_id and cyb.cost_budget_year = 2007
) left join drilldown_actual pya
on (p.sub_id = pya.sub_id and pya.cost_budget_year = 2006
) left join drilldown_actual cya
on (p.sub_id = cya.sub_id and cya.cost_budget_year = 2007
) left join drilldown_actual aya
on (p.sub_id = aya.sub_id
) left join drilldown_eac cyf
on (p.sub_id = cyf.sub_id and cyf.cost_budget_year = 2007
) left join drilldown_eac ayf
on (p.sub_id = ayf.sub_id)
where p.program_id = 818
group by p.sub_id, p.sub_name
feel free to mock my code and offer insight as to how to improve...
thanks
*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]