Unscramble the letters by letter frequency analysis You know those riddles where every letter is swapped for another letter?
E.g. you get a text like
JME JG EPP IFAPE EPJE CJPPPC BP,
      UIJCG JC EPP EFE GPJB EJIP EJ EJIP,
F EPJIG MPJEPPPP AJUC BJL UP
      GJP BL MICJIJMPPJUIP CJMI.

and are supposed to find out that it stands for
OUT OF THE NIGHT THAT COVERS ME,
      BLACK AS THE PIT FROM POLE TO POLE,
I THANK WHATEVER GODS MAY BE
      FOR MY UNCONQUERABLE SOUL.

This example was created by the following replacement matrix:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ODSXHKARFYGNBIQTJVCEWZMULP

Try to unscramble any given text by doing a letter frequency analysis. Assume that the most common letters in the given input are (left to right):
EARIOTNSLCUDPMHGBFYWKVXZJQ

Replace the most common letter in the input by E, the next most common by A, and so on
Producing a correctly unscrambled text is actually outside the scope of this challenge. That is, we assume that you get a correct result if only the input is large enough. (Testcase 1)
If there is insufficient data, your return value must be consistent with the data provided. (Testcase 2)
You may expect uppercase text only. It can contain digits, punctuations etc., which are not scrambled and to be output as is.

This is a code golf, shortest answer in bytes wins. Standard loopholes apply.
Testcase 1 - The shortest completely solvable one
CCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPPPPPPPPPPPPPPPPPPPPPIIIIIIIIIIIIIIIIIIIIIIIIFFFFFFFFFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPPPPFFFFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGGGEEEEEEEEEEEEEEEEEIIIIIIIIIIIIIIIITTTTTTTTTTTTTTTMMMMMMMMMMMMMMJJJJJJJJJJJJJAAAAAAAAAAAAAAAAAAAAAAAWWWWWWWWWWDDDDDDDDDBBBBBBBBBBBBBBBFFFFFFTTTTTJJJJWWWIIP

must output
EEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAAAAAAARRRRRRRRRRRRRRRRRRRRRRRRIIIIIIIIIIIIIIIIIIIIIIIOOOOOOOOOOOOOOOOOOOOOOTTTTTTTTTTTTTTTTTTTTTNNNNNNNNNNNNNNNNNNNNSSSSSSSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLCCCCCCCCCCCCCCCCCUUUUUUUUUUUUUUUUDDDDDDDDDDDDDDDPPPPPPPPPPPPPPMMMMMMMMMMMMMHHHHHHHHHHHHGGGGGGGGGGGBBBBBBBBBBFFFFFFFFFYYYYYYYYWWWWWWWKKKKKKVVVVVXXXXZZZJJQ

Testcase 2
HALLO WORLD must output ??EEA&lt;space&gt;?A?E?:

The 3 Ls turn into E
The 2 Os turn into A
The remaining letters are each replaced by an undefined permutation of the letters &quot;RIOTN&quot;, without any of these repeating.
JavaScript (V8), 185 bytes

c=&gt;(l={},[...c].map(i=&gt;l[i]=(l[i]|0)+1),e=Object.entries(l).sort((a,b)=&gt;b[1]-a[1]).map(i=&gt;i[0]).filter(i=&gt;parseInt(i,36)&gt;9),[...c].map(i=&gt;&quot;EARIOTNSLCUDPMHGBFYWKVXZJQ&quot;[e.indexOf(i)]||i))

Try it online!
Doesn't currently pass the second test case, but instead is based on OP's description of how the unscrambling works. The test case seems to be incorrect at the moment, as some groups of letters (like F or P) repeat letters.
Explanation:
c=&gt;(                            // Define arrow function with argument c
l={},                           // Create an empty object l
[...c].map(i=&gt;                  // For each character i in c...
  l[i]=(l[i]|0)+1),               // Increment l[i] (the number of times i appears)
e=Object.entries(l)             // Format l as an array [&quot;x&quot;, &lt;number of times &quot;x&quot; appears&gt;] in variable e
.sort((a,b)=&gt;b[1]-a[1])         // Sort e so most common characters are first
.map(i=&gt;i[0])                   // Get rid of number of times appeared
.filter(i=&gt;parseInt(i,36)&gt;9),   // Filter out non-letters using base 36 conversion :)
[...c].map(i=&gt;                  // For each character i in c...
  &quot;EARIOTNSLCUDPMHGBFYWKVXZJQ&quot;[   // Get the nth item from the frequency chart...
    e.indexOf(i)]                   // Where n is the index of i in e
    ||i))                         // Unless it isn't a letter, where i stays i