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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -