Hands: everybody who has no other rank. Rig sails, man guns, haul stuff, man ropes (most of the work on a ship has to do with pulling on ropes to some degree or another)
Mates: NCO's - keep discipline, carry out punishment and support junior officers. The First mate is the highest ranking non-officer on board ship, roughly equal to sergeant major.
Midshipmen - junior most officers, gun crew commanders, commanders of small squads
Lieutenants - more senior than midshipmen, and generally in command of such; on smaller vessels they are the XO (executive officer) of the ship; larger vessels have numerous lieutenants, listed from first (the highest) downward
Commanders - essentially glorified lieutenants, assigned their rank on the basis of ship availability (lose command of a ship and a commander returns to being a lieutenant)
Captains - Rank for comanding ships of the line (main battleships)
Admirals/Admirals of the Line - commanders of fleets of ships; the highest rank that still participates in sea travel
Rear Admirals - land based administrative officers
These are the ranks of the British Royal Navy as seen in the Hornblower series. The formality of these ranks is not common in previous eras (ie. Columbus fleet of three ships)
Extraordinary roles not incorporated above include:
Ship's surgeon - the guy who fixes people up.
Ship's cook (often known as the ship's doctor, for some reason)
Sailmaker; Ropemaker; Carpenter - for obvious reasons
Marines - soldiers assigned to do soldierly duties aboard ship - fight off boarders, guard prisoners and treasure, make raids against shore facilities.
In other times, many of the roles performed by ships officers were divided among other specialists, such as
Navigator - in charge of charts and reading the stars (frequently captains took this duty on themselves)
Pilot - the guy in charge of the wheel (more of a specialist skill than you might think)
Most of the time, a ship's crew spends its time aloft, tending to the sails, making sure they are trim (neither too tight nor too loose for the wind conditions); Sails are dozens of yards of canvas and hoisting them, even with the aid of pulleys, takes lots of strong men, as well as those aloft in the rigging; keep things clean and orderly; man the weapons in times of battle and try not to die from poor food, going over board or falling from the rigging.
That's what I know off the top of my head. Of course none of this is expert opinion and is subject to correction by more knowledgeable individuals.
Edit: check Agback's corrections to my land-lubber undrestanding, further down this thread.

Boy was I off.
Hope it helps.