sql - Get a value based on another column's value -
it's pretty basic sql statement imagine, can't life of me figure out how do.
so have table have 3 columns : amount of car sold (aocs), day of week (dotw), previous day of week (pdotw).
i'd have amount of car sold previous day in fourth column. example, let's have sold 4 cars on monday, 5 cars on tuesday, 3 cars on wednesday.
on tuesday line, i'd have '4' written, amount of cars sold on monday.
i'm not sure if make sense, let me know. thank help!
you have join table on itself
select a.dotw, a.aocs, a.pdotw, b.aocs my_table left join my_table b on a.pdotw=b.dotw
Comments
Post a Comment