I would say there are more kinds of endings than just the "happy" and "sad" ones. The ending to the director's cut of Blade Runner, for example, is ambiguous: we're left to wonder what'll happen to Rick and Rachael next. The ending of Clockwork Orange is happy for the bad guy, but not so much for anyone else. In a way, it's a "lesson" ending: evil as this young hoodlum was and is, his new political friends are even worse; in other words, don't let this happen to your country!
I'd also say that whether an ending is appropriate depends on whether it's consistent with the direction the rest of the story was taking. Some of the Grimm's stories do end very badly, but in many cases the ending is actually rather happy for the good guys--it's the bad guys whose torturous execution they describe in almost sadistic detail. (I think it was the evil queen in Snow White that they forced into red-hot iron shoes in which she had to dance until she fell down dead, for example.) A better example of a "sad" ending would be the one to The Thing; it was established throughout the film that this terrible creature from another planet was almost unstoppable. Having the good guys just win handily and waltz out of there would have downplayed their sacrifice. A pyrrhic victory is more fitting.
The ending to Clockwork Orange is likewise consistent: the film begins and ends with sick jokes that arouse moral conflict by making properly moral people laugh even as they also make them wince. The more light-hearted Death Race 2000's main character is more anti-heroic than villainous, producing less moral conflict in the viewer's mind, but the film likewise is one long tasteless joke, and ends consistently (with another tasteless joke). For a film that required a really bad ending, Requiem for a Dream is probably the best example. Sure, it's awfully depressing for everybody's hopes to be dashed, but then so is the whole film. Portraying drug addiction as enjoyable and morally uplifting would be a monstrous thing to do. (That's why Trainspotting gets less friendly reviews.)
As to whether sad endings sell... it depends, apparently. Grief and despair and forlorn feelings do seem to have some market for them, albeit a limited one. As early as in old Greek plays, people did have a liking for tragedy. Do Androids Dream of Electric Sheep? by Philip K. Dick (on which Blade Runner was very loosely based) suggested that people like having a feeling of empathy for characters who suffer. It suggested a need for catharsis as well: in the book, Deckard and his wife have a mood organ that allows them to dial for any feeling or emotion they can imagine. At one point, he has an argument with his wife and wavers between dialing for acquiescence and dialing for more venom to win the argument. (He decides to drop the argument when she warns him that if he tries to win, she'll dial for more wrath as well.) At another point, he's astonished to learn that his wife has put four hours of self-accusatory depression on her dialing schedule. Her explanation for this is that she just can't face the silence and loneliness of their apartment sometimes and needs something to fill those hours. In our time, lacking so convenient a device as the mood organ, depressing films may serve something like the same purpose.
There's also the Jerry Springer effect. I recall that Conan O'Brian once interviewed Montel Jordan about his career as a moderately successful trash TV host, and asked him why anyone wanted to be on his show. The best answer Montel could give, having asked them the same question himself, was that after doing all the lewd and despicable things they'd done in secret for so long, his guests just wanted to let it all out. They knew full well they were going to be held up to all the audience's opportunistic contempt and ridicule, but apparently they felt it was worth it. They may even have been desiring a little of the audience's cruelty as punishment. A film that inspires self-flagellating empathy might sell a few DVDs to this kind of audience.
In all cases, though, I think what decides the ending is the consistency of the film with what people are looking to see in it. Nobody who goes to see a Care Bears movie wants to see it end with the Care Bears all dying cruel deaths; it's aimed at young children, young children want there to be justice and mercy and happy endings all around, and a feel-good ending is practically required. Those of us who are older might want to see a satirical film in which the Care Bears all die at the end, but this still requires a happy ending, albeit by being funny rather than morally uplifting. In Shrek 2, on the other hand, there's something for both crowds courtesy of the writers making the Fairy Godmother turn out to be a cruel and ruthless villain under all her saccharine charm and giving her a well-deserved comeuppance. Then, for adults who are looking for an ultra-realistic ending, there's Flight 93, which was specifically arranged to provide a false hope for a happy ending that is crushed with the foregone conclusion we already knew from the true story on which it was based. The monstrous injustice of it is exactly what we went to see; any morally uplifting effect it might have on you is something you arrange for yourself.
In short, what kind of ending a film has should be determined by what the advertising promised the audience. If the advertising promises an uplift, it had better deliver it. If it promises us crushing grief and sorrow, it had better deliver that. If it promises a shock, it had better deliver whichever ending is more shocking.