sql - How to deal with DATE column of multiple tables -
i have 5 tables namely transaction, receipt, payment, wutran, mydates. mydates table contains dates.it has 1 single column dt. , remaining tables have 2 columns namely date,amount. have calculate sum of amounts these 4 tables group 'dt' column of mydates. query follows:
select m.dt, (sum(t.amount)+sum(r.amount)+sum(p.amount)+sum(w.amount)) sum_amount transaction t, receipt r, payment p, wutran w inner join mydates m on t.[date]=m.dt , r.[date]=m.dt , p.[date]=m.dt , w.[date]=m.dt group m.dt
but getting following error:
msg 4104, level 16, state 1, line 2 multi-part identifier "t.date" not bound. msg 4104, level 16, state 1, line 2 multi-part identifier "r.date" not bound. msg 4104, level 16, state 1, line 3 multi-part identifier "p.date" not bound.
can me out error......
error
because of join
applicable wutran
, mydates
, can try other condition where
it's not recommended.
try this
select m.dt,(sum(t.amount)+sum(r.amount)+sum(p.amount)+sum(w.amount)) sum_amount transaction t,receipt r, payment p, wutran w inner join mydates m on w.[date] = m.dt t.[date] = m.dt , r.[date] = m.dt , p.[date] = m.dt group m.dt
or have join
tables
select m.dt,(sum(t.amount)+sum(r.amount)+sum(p.amount)+sum(w.amount)) sum_amount transaction t join mydates m on t.[date] = m.dt join receipt r on r.[date] = m.dt join payment p on p.[date] = m.dt join wutran w on w.[date] = m.dt group m.dt
Comments
Post a Comment