These are different businesses. Walmart has a massive retail footprint, where Amazon does not.
Amazon’s huge 3p seller network means it can offer advertising as a revenue stream in a way Walmart can’t compete with.