sql - How to JOIN two tables on behalf of Max date -
i have tried following. query working returning more rows not expected.
select x,y,z (select (t1.hour*4) + int (t1.minuts/15 ) +1 x,t1.amount y, t1.date,t2.amount z table1 t1 inner join (select * table2 date=(select max(date) table2 ))as t2 on t1.store=t2.store t1.date = (select max(date) table1 ))
sample data:=
store date day_of_wk hour minuts amount 574 13-03-2017 2 0 0 0.00 574 13-03-2017 2 0 15 0.00 574 12-03-2017 2 0 30 0.00 574 11-03-2017 2 0 45 0.00 574 11-03-2017 2 1 0 0.00 574 13-03-2017 2 1 15 0.00
both table having same data there different business logic on amount column.
what need amount , time id both tables of max date.
solved following query=>
select t1.id x,y,z (select (hc.hour * 4) + int (hc.minuts/15 ) + 1 id, amount y, date table1 hc date = (select max(date) table1))t1 left join (select (hs.hour * 4) + int (hs.minuts/15 ) + 1 id, amount z, date table2 hs date=(select max(date) table2 ))t2 on t1.id=t2.id
Comments
Post a Comment