The tune is "What Can the Matter Be?", also known as "Johnny's So Long at the Fair", is a traditional nursery rhyme that can be traced back as far as the 1770s in England. The Oxford Dictionary of Nursery Rhymes by Iona and Peter Opie traces this song back to an earlier folk ballad, recorded between 1770 and 1780.
"Seven Old Ladies" is a bawdy parody of the old tune.
I learned it from Oscar Brand's recording.