This is attributed to Sir Richard Burton. I found in on the groaners listserv.
A friend of mine once spent a night in an old house that reputedly was haunted by the spirit of Sir John de Bermingham. He did this for a bet, armed only with advice on what to do should he encounter Sir John: He must hum a certain passage by Mozart, but under no circumstances. leave it unfinished or the wretched wraith would then wreak terrible vengeance. Should he succeed in completing the passage, Sir John would leave him in peace.
All went well until the stroke of three. Suddenly, the phantom appeared! Prepared for this, my friend began to hum quietly but precisely the passage, as he had been taught. Nearing its end, he was relieved to note that Sir John’s features were placid. Suddenly, however, a second spirit appeared over Sir John’s head! This caused my friend to lose his concentration and leave the passage unfinished. An unearthly snarl burst from the ethereal lips of Sir John followed by a stream of curses. In terror, my poor friend fled from the house.
I paid a visit recently to see him. He is now bald and toothless, wasted and bedridden. Curiously, as I was going into his house, I met at his gate the man who had been the other party to the bet on that fateful night. After, being shown into our friend’s room, we both leaned over his bed to cat catch the wheezed greeting.
“Tell me,” pleaded the poor soul, “What did I do to deserve this?”
The other man thought for a moment and then asked gently, . . . “Did your shooing hum lose its quaver on the dead ghost over knight?”