The easiest way to compare sensors is to use DXOmark, see the link below.
https://www.dxomark.com/Cameras/Compare/Side-by-side/Pentax-K-3-versus-Penta...___914_811_639
However, that doesn't necessarily tell the whole story. It doesn't include colour rendering, attractiveness of grain or all other factors. Here we see the K3 gets a slightly better score than the K30 and both score significantly better than the K-x. I, and many others, don't worry about megapixels at all. I was happy with the ten megapixels of my K200D and don't worry when using my 16MP Fuji camera even though it has a third less than my K3.
There's MUCH more to comparing sensors than megapixels. The point I wanted to make is that you don't necessarily get a better sensor in a more expensive camera, even if it's a "pro" level camera. "Better" is also open to interpretation - high ISO image quality is useless to someone who always shoots in good light or in a studio with a full lighting rig. What you get with a better camera is a more solid build, more options, more controls to be able to change settings without menus, better AF system etc etc. However, none of that means that you need better lenses to put on it. Good lenses are always good no matter what camera they're on.