You hear this phrase in dozens of movies and TV shows, as well as in everyday use.
Does anyone actually know where it comes from? My hunch is that it probably comes from a movie as opposed to some heroic ancient general, but my mind is open.
Someone said something similar, and it was recorded, by Plutarch, regarding a Pyrrhic victory, which happened around 200 BC, check the wikipedia reference 3.
If you’re looking for a cool movie reference, you’ll have to search deeper, but it is a pretty trite phrase – people argue, get in over their head, and succeed only by wasting resources. The first person to say it was probably a Cro-magnon to a Neanderthal, banging a rock against a rock.
Or “we won all the battles but lost the war” means that one side had military expertise and might but lacked the resources and/or support back home to carry on a sustained conflict.