I'm basically asking by what merits they got in and how did one get appointed.
Nominally there were only two true groups of people in dynastic society: the emperor and family (who ruled via the mandate of heaven, and were thus at the top) and everyone else. But, for the early part of China's history (pre-Han), getting a government position as a non-appointed aristocrat was virtually impossible. While the examination system was put into place around the time of Qin's Shi HuangDi, it really wasn't until the Tang dynasty that the system became less based on connections (that good ol' 关系, guanxi) of the aristocracy and more based on merit. Much of this can be attributed to Wu ZeTian.
That doesn't mean that just anyone could succeed though; the tests were still heavily skewed towards those who could afford quality education. The basic tests during the Tang dynasty consisted of things like an oral examination (of the elite dialect; regional dialects were not acceptable), a test on knowledge of Confucian material, and other philosophical material. The tests were most often administered in small huts with some boards to make a bed (the tests were quite lengthy) or cubicles. From there, depending on how well one did or what test they were taking, there were quite a few different certifications you could achieve that opened up various levels of government positions. Throughout the history of the imperial exams, there were still those who got appointed by connections, but the system made government positions more accessible to lower classes as time went on.