The Pilot, Where No Man Has Gone Before, has several lieutenant commanders (LCdr) on board. There is no clear distinction.
However, it's been customarily assumed that Mr. Mitchell was the first officer until his death.
In the run of the series, we see the following LCdr ranked personell:
Gary Mitchell (C.Helm), Spock (C.Sci), Scott (C.Engr), McCoy (C.M.O), Giotto (C.Sec), Finney (C.Rec.).
We know that, after episode 1, Spock is the executive officer as well as Chief Science Officer;
Making Sense of things.
It is important, however, to understand several elements of "Naval Tradition" to make sense of things.
Line of Command vs Chain of Command
The Chain of Command differs for almost everyone aboard - only the Commanding Officer, Vice Commander, and Executive Officer are in everyone else's. Chain of command is "Who do I get orders from, and to whom do I give orders?" - Unless you're the captain, someone is above you aboard.
The Line of Command is who takes over when. It's not as simple as just rank - rank figures, but isn't the sum total. Note that the term is now fairly archaic; it's not used much, and modern military use conflates it with Chain of Command, but conceptually, they are different, so I will use the archaism for clarity.
Line vs Staff
Navies have almost always distinguished officers into two or three broad groups: Line Officers, Restricted Line Officers, and Staff Officers.
Line officers are trained for ship command; part of their training includes how to Conn a ship, and how to handle a large number of administrative and tactical functions.
Restricted Line are usually aviators or engineers. Many navies don't use this category; some did, but don't any more. Restricted line officers can have positional line-of-command, but if they don't they come after the unrestricted line officers. For certain eras, Gunnery Officers might be Restricted Line,
Staff Officers are persons given officer rank for purposes of authority, but who are not in the line of command.
We can strongly infer a Line vs Staff distinction in TOS/TAS, and it's pretty clear; we cannot make a clear case for Restricted Line officers, but there is a weak inference.
The Line of Command is traditionally Commanding Officer, Vice Commander, Executive Officer, Chief Operations officer, Chief Engineer. Vice Commander is not often used on ships; it's common for higher commands. First Officer may be either the Vice Commander (if there is one) or the Executive Officer.
The normal for ships, and due to TOS dialogue, we know that it's the case for TOS, is an Executive Officer as First Officer, since Kirk uses both terms for Spock.
Chief of Operations would be the seniormost officer Helmsman or Navigator. Chief Engineer is the Seniormost Engineer.
We do not know which was first officer during the Pilot Episode - It could be Mitchell or Spock. Given that Mitchell is in a position in the line of command already, and in command division, we can make a reasonable but weak inference that it's likely Mitchell, and the prior Exec either was transferred or killed prior.
A Captain normally has a Commander (CDR) for an Executive officer. We do not see a full commander until Scott and Spock are promoted to that grade.
Conn vs Command
The Conn officer is the officer in operational control of the vessel for a given watch. Conn officers may or may not be in the line of command - many line officers get an occasional shift as the Conn. It doesn't mean they are in the line of command.
Any time the senior watchstander has to leave the bridge, he should (and in TOS, we see them do so) tell someone else they have the Conn. We see a number of Lieutenants take the conn. But we never see Uhura take the Conn.
Authority vs Command
Within their area of competence, a staff officer can give orders, and expect them to be followed. Certain officers can give orders to their superiors even - CMO and Chief Psychiatrist within their professional capacity, JAG/Legal on matters of law. Doing so is a touchy issue - it can make or break careers.
The evidence for Line vs Staff
We have three ranking LCdr types who neither take the Conn nor take command: McCoy, Giotto and Finney.
McCoy is the CMO - as a doctor, he's probably not trained for Conn duty, and his routine duties take most of his time.
Giotto is the Chief of Security. Again, his duties probably do not require him to be trained in commanding the ship.
Likewise, Finney is a line officer; we know his training was as a line officer. But he's assigned into a position that is a staff-type position, and never takes the Conn. (Reality - Guest Star.) So we can argue that he's been removed from the Line Officer category. Since he's still in green, we can weakly infer he might be restricted line - taken out of the primary line of command, but not prevented from taking conn watches.
Further, there is Uhura. Uhura does not take the conn, and has a replacement to hand the few times she's taken on away missions. It is thus a fair inference that she's a staff officer.
Science and Medical would normally be staff. Security would be staff, tho' not all the guys on Guard details are full time security - some are also rated in other fields.
So, who goes where?
We will assume, for now, no restricted line, and that Finney was right after the "top four." Sulu goes after Scott because Scott's got more experience, and it's implied he's a line officer as well. Some flexibility happens when a senior engineer is faced with a Junior Ops.
We will also assume that, excepting those Ops personell who cross trained into engineering, the other Engineering lieutenants and ensigns we see are staff officers.
The Line of Command
CO: Capt. Kirk
XO: during the pilot, either LCdr Mitchell or LCdr Spock; after, Cdr Spock
C. Ops: LCdr Mitchell
C. Engineer: LCdr Scott
C. Ops: Lt. Sulu †
Line, rows by seniority; alpha within row:
Lts. Bailey, Farrell, Leslie, Riley, Stiles
Lts. DePaul, DeSalle, Hansen, Hadley, Painter, Spinelli
Lts. Kyle, Rahda
Ens. Chekov, Haines
C. Sci: LCdr Spock
C. Records: LCdr Finney (after science because it is an exploration vessel)
C Security: LCdr Giotto
C. M. O.: LCdr Dr. McCoy
C. Psych: Lt Dehner
C. Comm: Lt Uhura
(assorted Sciences,Engineering, and Support Services Lieutenants)
M.O.: Dr. M'Benga (presumably a Lt.)
(Assorted LtJGs in Sciences, Engineering and Support Services)
M.O.: Ens Nurse Chapel
17 operations officers are listed. We know there are three bridges, and 3 shifts, and 2-3 seats for Ops persons in each: Conn, Helm, Nav. And the Conn officer might not even be present in the Emegency or auxiliary; the CO, XO, and someone else rotate the Conn on the main bridge. So, that leaves room for 24 operations types, and a minimum of 18. We know most of the department.
We don't know most of the engineers.
We do see a lot of security guards, but most don't have names. Security are likely staff officers, tho' we see a couple line officers "slumming" in security. (Reality - recycled extras.)
Most of the Science officers are likely staff officers. A few might be in the line, and some line officers do a good bit of science - Sulu is rated in Astrophysics and xenobiology...
We do see some mobility into/out-of the line.
We know that the line/staff distinction is canonical for Trek - it's the focus of an Episode of TNG, as Troi becomes a qualified watch officer (and thus line officer). Again, no specifics of restricted vs unrestricted, but since Crusher ranks several others who do take over, the inference to make is that there is a restricted line distinction.
Generally, within non-line officers, Engineers would tend, historically, to be the priority within a rank, then gunners, then admin, then last, medical. Given that Sciences are a priority, and Roddenberry's insistence that there were no enlisted, as with NOAA's commissioned corps, we'll put non-line sciences at the top of the pile. So, once you're out of line Ensigns, you go to the Staff Commanders, then Lieutenant Commanders, then lieutenants, then Lieutennants Junior grade (and yes, there is photographic evidence for them), then Ensigns. Within each rank, Sciences, then engineers, then security, then other support services, then medical. Within each department, whoever had the rank longest gets it first. Chapel is probably the 2nd to last officer - we see another unnamed nurse in at least one episode. Memory Beta has Hinch and West as additional nurses.