Comedies often provide(d) the best opportunities for musical interludes and the majority of my memories are centered are around sitcoms.
Classic TV shows are a veritable font of musical interludes. Ricky and Lucy, Fred and Ethel had endless numbers...Mary on The Donna Reed Show...Ricky on The Adventures of Ozzie & Harriet...the list goes on.
The Dick Van Dyke Show had some of the best numbers, though. Rob and Laura singing and dancing, Rob's brother Stacey, Buddy and Sally, and even Mel got into the act. My favorite performance was that of "I Am A Fine Musician", which was used twice during the series run.
This version is fine, but the better of the two is from the episode from Season 2, Ep 24 "The Sam Pomerantz Scandals". I've not found a clip from that episode, though.
Jumping ahead a few decades, there's no shortage of TV-based singing and dancing. Scrubs had more than a few episodes with music montages (anyone remember "Talk Dirty To Me" as sung by Carla and Ted?) Roseanne, for ill or for good, featured its fair share of songs (let's forget Roseanne's trial and focus on Dan singing "Jailhouse Rock" with the great John Juke Logan playing harmonica in the background...which reminds me that he also appeared on Home Improvement doing the same thing).
Then we have Harry's dream from the season two 3rd Rock From The Sun episode, "Nightmare on Dick Street, Part 2". Great Randy Newman tune that also includes an appearance by Newman at the 2:21 mark in this clip. Rubber-faced, spaghetti-limbed French Stewart did a bang up job with "Life Has Been Good To Me". Then again, I'd watch the show even if they'd never gone done this particular musical path. But they did, and it was perfection.
Bonus clip: From Mad About You and special guest star Mel Brooks. Forward to 6:21 and dance and sing along to the "Turkey Trot".