[Question]
  [
It is very hard to remember my password, so I came up with a way to generate a password.
The way I generate my password is from a word or a sentence, following these steps:
1. Start from left to right
2. Find the count of each letter
3. Put letter with its count in an order 
	* Letters with higher repetition will be in the end
	* Letters with the same repetition will be ordered alphabetically
4. Numbers and special letters will be ignored including whitespace (e.g. 9, 4, @, (, \*, etc. are ignored)
5. Group letters ignoring case. In the output, use the case of the last occurrence in the input
6. The count of the letter can be any number e.g. 5H17M345K
7. If input is all numbers or special letters then output will be empty string e.g. Input "12$\*34^!" then output ""
8. when order for the same occurrence alphabetically case does not matter e.g. 1a1B1c
Example:
```
Input: Kitkat Tango
(2k / 1i / 3T / 2a / 1n / 1g / 1o)
Output: 1g1i1n1o2a2k3T
```
Another example:
```
Input: Database Partitions Task
(1D / 5a / 4T / 1b / 3s / 1e / 1P / 1r / 2i / 1o / 1n / 3s / 1k)
Output: 1b1D1e1k1n1o1P1r2i3s4T5a
```
Note: the letters with 1 repeat are in the beginning ordered alphabetically
then the letters with more reps
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the shortest code wins.
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~19~~ ~~17~~ 16 bytes
Saved 1 byte thanks to *Kevin Cruijssen*
```
áΣl}.γl}éεgyθJ}J
```
[Try it online!](https://tio.run/##ATgAx/9vc2FiaWX//8OhzqNsfS7Os2x9w6nOtWd5zrhKfUr//0RhdGFiYXNlIFBhcnRpdGlvbnMgVGFzaw "05AB1E – Try It Online")
or as a [Test Suite](https://tio.run/##yy9OTMpM/V9TVvn/8MJzi3Nq9c5tzqk9vPLc1vTKczu8ar3@V9orKejaKSjZ6/z3zizJTixRCEnMS8/nckksSUxKLE5VCEgsKsksyczPKwbKFGcDAA)
**Explanation**
```
á                  # keep only letters in input
 Σl}               # sort by lower-case
    .γl}           # group by lower-case
        é          # sort by length (stable)
         ε    }    # map each to
          g        # its length
             J     # joined with
           yθ      # the last letter
               J   # join to string
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~66~~ 63 bytes
```
{[~] map {+$_~.tail},sort {+$_,.lc},m:g/<:L>/.classify(&lc){*}}
```
[Try it online!](https://tio.run/##HcmxDoIwEADQna@4gVDQpmwORJzcdHBwM4achJKGQknvFtKUX6/G9b118PaU5g0KDW0Kr/0NM64Qjnm3K0ZjoyTn@Q9S2T7KuRnrc3O/1Kq3SGT0Vha2r8IhxkS4gS7zrgLtfCZuhidkeOIyOiEzcUXGD9IAD/Rs2LiFfkmTkOkL "Perl 6 – Try It Online")
### Explanation
```
{                                                             }  # Anon block
                                    m:g/<:L>/  # Match all letters
                                             .classify(&lc)  # Group by lowercase
                                                           {*}  # Get hash values
                     sort {+$_,.lc},  # Sort by array length and lowercase
     map {         },  # Map to
          +$_~.tail  # Concat array length and last letter
 [~]  # Join
```
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 105 bytes
```
x=>x.Where(char.IsLetter).GroupBy(a=>a%32).OrderBy(a=>(a.Count(),a.Key)).Select(a=>a.Count()+""+a.Last())
```
[Try it online!](https://tio.run/##hU67CsJAEOz9CgkIt6hXaKlJ4RMxoKBgvTmX5FAvsrsB/foYX42NUw3zYpz0nfh6UQU3FmUf8t5qHqoLMWZn@khJoiQa17c4udlDQUzGFch2JSmpEoNdclldJ3eDcYKd4QDsho/Eb8GgnZZVUAM9tGu6A9gdncnpK/31ulHURZuiNBzqUevAXin1gcz7Q5MLDtU8n5ho7fWE2t5jyMtfRADwrz9DxQyF2ltk9erLIM2YnF7d@gE "C# (Visual C# Interactive Compiler) – Try It Online")
Thanks to dana for bringing it down to 105 bytes from 138 bytes.
[Answer]
# [Japt](https://github.com/ETHproductions/japt) v2.0a0 [`-P`](https://codegolf.meta.stackexchange.com/a/14339/58974), 14 bytes
```
f\l üv ñÊ®ÌiZÊ
```
[Try it](https://ethproductions.github.io/japt/?v=2.0a0&code=ZlxsIPx2IPHKrsxpWso=&input=IktpdGthdCBUYW5nbyIKLVA=)
```
f\l üv ñÊ®ÌiZÊ     :Implicit input of string
                   > e.g., "Kitkat Tango"
f                  :Split to an array of characters
 \l                :  Matching RegEx /[a-z]/gi
                   > ["K","i","t","k","a","t","T","a","n","g","o"]
    ü              :Sort & group (Preserves original order within each group)
     v             :  By lowercase
                   > [["a","a"],["g"],["i"],["K","k"],["n"],["o"],["t","t","T"]]
       ñ           :Sort
        Ê          :  By length
                   > [["g"],["i"],["n"],["o"],["a","a"],["K","k"],["t","t","T"]]
         ®         :Map each Z
          Ì        :  Last element of Z
                   >   ["g","i","n","o","a","k","T"]
           i       :  Prepend
            ZÊ     :    Length of Z
                   >   ["1g","1i","1n","1o","2a","2k","3T"]
                   :Implicitly join & output
                   > "1g1i1n1o2a2k3T"
```
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~67~~ ~~66~~ ~~41~~ 39 bytes
```
\P{L}
O$`.
$l$0
ir`\1*(.)
$.0$1
N`\d+.
```
-25 bytes and a minor bug-fix thanks to *@Neil*.  
-2 bytes thanks to *@Neil* and *@Shaggy* together.
[Try it online](https://tio.run/##K0otycxLNPz/Pyag2qeWi8tfJUGPSyVHRY0rsyghxlBLQ0@TS0VPTcWQyy8hJkVb7/9/l8SSxKTE4lSFgMSiksySzPy8YoWQxOJsBQfFeEMjYwA) or [verify all test cases](https://tio.run/##K0otycxLNPyvquGe8D8moNqnlovLXyVBj0slR0WNK7MoIcZQS0NPk0tFT03FkMsvISZFW@//f@/MkuzEEoWQxLz0fC6XxJLEpMTiVIWAxKKSzJLM/LxioExxtoKDYryhkTEA).
**Explanation:**
Remove everything except for upper- and lowercase letters:  
i.e. `Kitkat Tango 123!` → `KitkatTango`
```
\P{L}
```
Sort the individual letters case-insensitive ([thanks to *@MartinEnder* for this](https://codegolf.stackexchange.com/questions/148228/sort-an-option-string/148231?noredirect=1#comment431171_148231)):  
i.e. `KitkatTango` → `aagiKknottT`
```
O$`.
$l$0
```
Capture every chunk of case-insensitive repeated adjacent letters:  
i.e. `aagiKknottT` → [`aa`,`g`,`i`,`Kk`,`n`,`o`,`ttT`]
```
ir`\1*(.)
```
Prepend the length of every match, and only keep the last letter of every chunk:  
i.e. [`aa`,`g`,`i`,`Kk`,`n`,`o`,`ttT`] → `2a1g1i2k1n1o3T`
```
$.0$1
```
Sort the numbers and letter groups based on the numbers:  
`2a1g1i2k1n1o3T` → `1g1i1n1o2a2k3T`
```
N`\d+.
```
After which the result is output implicitly.
[Answer]
# [Python 3](https://docs.python.org/3/), 105 bytes
```
s=input()
t=s.upper()
for n,c in sorted((t.count(i),i)for i in{*t}if'@'<i<'['):print(n,end=s[t.rfind(c)])
```
[Try it online!](https://tio.run/##Fco9CgIxEEDh3lOkm0SWNHayAQsPYLHdYhHzg4MwCZlJIeLZY@wefK@@5VnoNAY7pNpFm4M4tr3W1Gbn0hQtQSEpLk1S1FpsKJ1Eo1nQ/B2nfo7yxQwXWHGFHcy5NpwPLYmi411sy0hRB3M3Y8DVi394Turmm6BgIVab5xf8AA "Python 3 – Try It Online")
-1 thanks to [ArBo](https://codegolf.stackexchange.com/users/82577/arbo).
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~102~~ ~~96~~ ~~93~~ 87 bytes
```
""<>Map@ToString/@Sort[(r=Reverse)/@Tally[r@#/." "->Nothing,Equal@@ToLowerCase@{##}&]]&
```
[Try it online!](https://tio.run/##FU7Pa8IwFL77VzxSEJVqeNXdpgR0p7lRZm6lh6fENrQ2W/JURunf3mXH7/d3I67NjdheaLzCFkYhXncf9K20O7G3XSXVyXkuZn77ZR7GBzOXSlPb/hZeJXIlQCx3n47raE3ffu7Uqhg9uqfxewpG9UkyTMtyOlIs78W75YYYNHWVEymIAzGdow9y8mzZui5EMTRiACkh/ij2NXm6cFwuJ5M8PuLiKhVFALMF9FihxQ5dRlmz1ingGQ9osPnnMEef2XXY6BcaYDEf/wA "Wolfram Language (Mathematica) – Try It Online")
```
Tally[r@#/." "->Nothing,Equal@@ToLowerCase@{##}&]      Start with a char list
        #/." "->Nothing                                Remove spaces
      r@                                               Reverse the result
Tally[                 ,Equal@@ToLowerCase@{##}&]
                                             Make a list of letters and multiplicities,
                                             where two letters are considered the same if
                                             their lowercase values are equal. Then:
""<>Map@ToString/@Sort[(r=Reverse)/@ ... ]&
                       (r=Reverse)           Reverse each {letter, freq} to {freq,letter}.
                                             Then the standard Wolfram order function sorts
                                               lower frequencies first, with ties broken by
                                               by letters earlier in the alphabet,
                  Sort[                  ]     exactly what we want.
    Map@ToString/@                           @ has higher precedence than /@, so
                                               this effectively does Map[Map[ToString]].
""<>                                         StringJoin the nested list into a single string.
```
[Answer]
# Pyth, ~~27~~ ~~24~~ 22 bytes
```
ssrD0m,lded.gr0k@+Gr1G
```
Try it online [here](https://pyth.herokuapp.com/?code=ssrD0m%2Clded.gr0k%40%2BGr1G&input=%22Database+Partitions+Tasksssssssssss%22&debug=0).
```
ssrD0m,lded.gr0k@+Gr1GQ   Implicit: Q=eval(input()), G=lowercase alphabet
                          Trailing Q inferred
                   r1G    Uppercase alphabet
                 +G       Concatenate with lowercase alphabet
                @     Q   Keep those characters in Q which are also in the above
           .g             Group the remaining characters, as k, using:
             r0k             Convert k to lowercase
                              (Grouping preserves relative order)
     m                    Map the sorted groups, as d, using:
       ld                   Length of d
      ,                     Pair the above with...
         ed                 ... last element of d
   D                      Sort the above...
  r 0                     ... by their lowercase values
ss                        Flatten, then concatenate the result of the above into a string, implicit print
```
*Edit: Golfed 3 bytes by ordering by character before group, previous version: `sm+ldedo,lNr0eN.gr0kf}r0TGQ`*
*Edit 2: Golfed off another 2 bytes by formatting output before any ordering, previous version: `sm+ldedlD.gr0krD0f}r0TGQ`*
*Edit 3: Golfed off another byte by changing the filter, thanks to @FryAmTheEggman. Also had to fix a bug when OP clarified that a single letter can appear more than 9 times, which added a byte back on :o( Previous version: `srD0m+lded.gr0kf}r0TGQ`*
[Answer]
# Perl 5 (`-n`), ~~74~~, ~~68~~, ~~66~~, 65 bytes
-6 bytes changing `-p` to `-n` and using `say` instead of `$_=join"",`  
-2 bytes thanks to Abigail using `\pL` instead of `[a-z]`  
-1 byte thanks to Kjetil S. removing `i` flag no more necessary after using `\pL`
```
s/\pL/($h{lc$&}+=1).=$&/ge;say sort{$a-$b||lc$a cmp lc$b}values%h
```
[TIO](https://tio.run/##PYqxDsIgFAB3v4KBNm0MxQ6dGjY3NXFwdHk0pDRFIDw0MW1/XSQO3nSXnFfBdKnQoqr7hPzuz7yiejEDLbe9aOtG0JKPqkd4E3QhLhQYleuaByDDw5MscnuBeSosdEqnKc4QyQ3s6P7sjhBBAipyhRCnODmLecH54/wvErt0zaFNzH4B)
58 bytes, in case there is no more than 9 occurence of each character
```
s/\pL/($h{lc$&}+=1).=$&/ge;say sort{lc$a cmp lc$b}values%h
```
[Answer]
# [Python 2](https://docs.python.org/2/), 116 bytes
```
def f(s):a=s.lower();return''.join(`n`+s[a.rfind(c)] for n,c in sorted((a.count(c),c)for c in set(a)if c.isalpha()))
```
[Try it online!](https://tio.run/##Pc0xSwNBEIbh3l8xYHE7GBb2oo1il84mxXUiZLK3m4wXZo6dCeKvPy8K1s/38s3fflbpl2UsFWowfKZXixf9Ki3gSyt@bdJ18VNZwkEOD/ZOsVWWMWT8gKoNZJOBBUyblzEEilmv4itvMt78T4sHQq6QIxtd5jMFRFzmxuLrbffGPpHDQHLSDuE@nRInSdpTP22Hu//djpyOZAX21JydVWyNbPptjmmXSppuXdqn1vPWHocnWn4A "Python 2 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), ~~114/113~~ 105 bytes
-9 bytes thanks to [Laikoni](https://codegolf.stackexchange.com/users/56433/laikoni) (using list-comprehension and `(||)` instead of `filter` with `elem` & shorten `length` to get rid of ugly `zip`)!
```
f s=id=<<[show(h r)++[last r]|l<-[1..h s],a<-['A'..'Z'],r<-[[x|x<-s,x==a||x==[a..]!!32]],h r==l]
h=length
```
[Try it online!](https://tio.run/##XZHRSsMwFIbv@xRnRehGu0I2vRnNhbgLUZGBA8FaJLNZG1qTkZyxbvTaB/ARfZF6OgWnN@Gc5P@/8ycphatkXXfdGhxXOU@S1JVmNyzBjsIwrYVDsFlbJ@OUxXEJLosE1cFlEMfBU5BFlrq0aZtk7KKGc9G2tKYijrPBYDrJsohInNeZV/Ja6gLL7k0oDRxy4wH4tworgbAUujA@fL5/wM2WRvqsYIppZiZiUk2Xfi@dCxQr4SQshEWFymhHPlf9sa3YnElW9Va2YHaipu58eSF6wLCX3RsslS5GQDeFQuKV0Sg1Os9rfjEHUrewB87hQEk3W3xAe6fhDPq3gQbCEL6n@n153NwfPUSXdqcoJIe1UDVZfNls5CvKfHaiPhwRz1gYnP2D7Igg@@GwhuYn1Qt1J/mGdDLqrunfTASPxtb54As "Haskell – Try It Online")
[Answer]
# [Red](http://www.red-lang.org), ~~220~~ ~~196~~ 206 bytes
```
func[s][a: charset[#"a"-#"z"#"A"-#"Z"]trim/all form sort/skip collect[foreach c sort
unique reverse rejoin parse s[collect[any[keep[a]| skip]]][i: 0
foreach d s[if(c% 32)=(d% 32)[i: i + 1]]keep i keep c]]2]
```
[Try it online!](https://tio.run/##bYwxT8MwEIX3/IrTRZWKECqULRIDMxti4nTDyTlTN6kdbAepFf89tSOViVve0733vqj98q49cWM7WOzsDSUm6cAcJCbN1KLgQ4sXbPG1mk/kHN1pJ@MINsQTpBDzLg1uAhPGUU2m8lYxBzBr1szefc8KUX@0EIseg/MwVTwkuo3En2lQnUj4FyqOmcl18NjccH1pO7s1G3je371s@1VrxcE9PDHXdfGrGOY9L1N0PoMFfHN5kAwf4r/C32Hzb47LFQ "Red – Try It Online")
Thanks to Shaggy for finding a bug.
[Answer]
# [Scala](http://www.scala-lang.org/), 103 bytes
```
_.filter(_.isLetter).groupBy(_%32).values.map(l=>l.size+""+l.last).toSeq.sortBy(_.toLowerCase).mkString
```
[Try it online!](https://tio.run/##XY5NawIxEIbPu79iWBASLHOwt8IuWHpsQbD3ZdTpEo1Jmhm1Kv72dKngoaf3ObxfsiZPJa62vFb4IBeAf5TDRmCeElzrqq6O5GHgwJmUFyRyinnzAkvNLgzQdg8qPX45r5xNj07eWUe0OOR4SK9n00@eZxbHrgML7ikZ33YexV142jRTj55ELWpc8jdKzDpGpO2M/FmexFrc7@5LpUqjqA/m/yvTvJHSioRhQVmduhgEPkl2jbX1rZRf "Scala – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
fØẠµŒlĠLÞịµL,Ṫ)
```
A full program printing the password as specified (as a monadic Link it yields a list of lists each containing an integer and a character).
**[Try it online!](https://tio.run/##AT0Awv9qZWxsef//ZsOY4bqgwrXFkmzEoEzDnuG7i8K1TCzhuaop////RGF0YWJhc2UgUGFydGl0aW9ucyBUYXNr "Jelly – Try It Online")**
[Answer]
# [Husk](https://github.com/barbuz/Husk), 15 bytes
No problems with imports when using Husk, therefore we can make use of the various handy functions such as `groupOn`, `sortOn`, `toLower` etc:
```
ṁ§:osL→ÖLSġÖ_f√
```
[Try it online](https://tio.run/##AS4A0f9odXNr///huYHCpzpvc0zihpLDlkxTxKHDll9m4oia////S2l0a2F0IFRhbmdv "Husk – Try It Online") or [try them all!](https://tio.run/##AVwAo/9odXNr/23Cp28rYCsiIC0@ICJzb3PigoHCtv/huYHCpzpvc0zihpLDlkxTxKHDll9m4oia////S2l0a2F0IFRhbmdvCkRhdGFiYXNlIFBhcnRpdGlvbnMgVGFzaw "Husk – Try It Online")
## Explanation
```
ṁ§:(sL)→ÖLSġÖ_f√  -- example input: "Kitkat Tango"
              f√  -- `filter isAlpha`: "KitkatTango"
          S  _    -- apply _ to .. then ..
            Ö     -- | sortOn: `sortOn toLower`
           ġ      -- | groupOn: `groupOn toLower`
                  -- .. compose: `groupOn toLower . sortOn toLower`
                  -- `sortOn toLower` (stable): "aagiKknottT"
                  -- `groupOn toLower`: ["aa","g","i","Kk","n","o","ttT"]
        ÖL        -- `sortOn length` (stable): ["g","i","n","o","aa","Kk","ttT"]
ṁ                 -- map and flatten (`concatMap`)
 §                -- | fork argument ..
       →          -- | | `last`: ['g','i','n','o','a','k','T']
   (sL)           -- | | `show . length`: ["1","1","1","1","2","2","3"]
  :               -- | .. and `snoc`: ["1g","1i","1n","1o","2a","2k","3T"]
                  -- : "1g1i1n1o2a2k3T"
```
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 28 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Anonymous tacit prefix function.
```
(∊⍤∧⌊(⊂⍕⍤≢,⊢/)⍤⊢⌸⊢)'\PL'⎕R''
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/X@NRR9ej3iWPOpY/6unSeNTV9Kh3KojfuUjnUdcifU0Qu2vRo54dQFJTPSbAR/1R39QgdfX/aY/aJjzq7QPyPP0fdTUfWm/8qG0ikBcc5AwkQzw8g/@nKah7Z5ZkJ5YohCTmpefDgToA "APL (Dyalog Extended) – Try It Online")
`'\PL'` non-letters  
`⎕R` PCRE **R**eplaced with  
`''` empty strings
`(`…`)` apply the following tacit function:
 `⌊` with the lowercase as keys,  
 …`⌸` apply the below tacit function to each key and its corresponding set of values, namely  
 `⊢` the argument:
  `(`…`)` apply the following tacit function  
  `⍤` to  
  `⊢` the list of values:
   `⊢/` the last value
   …`,` prepend the following to that:
    `⍕` the stringification  
    `⍤` of  
    `≢` the tally
   `⊂` enclose (to treat character list as single string)
 `∊` **ϵ**nlist (flatten)  
 `⍤` the  
 `∧` sorted-ascending version of that
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 127 bytes
```
s=>[...s].sort(o=(x,y)=>p(0+x,36)-p(0+y,36),p=parseInt).join``.match(/([a-z])\1*/ig).map(x=>(l=x.length)+x[l-1]).sort(o).join``
```
[Try it online!](https://tio.run/##NY2xTsMwFEV3vsKb/UjiUiGxIGeiQ8XCwJZG6iM4qVvjZ9lPyOXngyvBdI/uke494zfmKbnIXaBPu85mzaYftNZ51JkSKzKqtFcwfVQPTWkfn6C70fVGbTQRU7b7wKDP5MLxqL@Qp5PaqAG7nxEO2/uNW6C2URXTK2@K9jYsfIKmDL7bjvB38z@wshnkq@MLsnjHsJBshXxBxg/MVrxhYseOQq4yX@T4fMd6prTDesqmn6ohb7WnRbFohDwEWWNWDADrLw "JavaScript (Node.js) – Try It Online")
* `parseInt(numberAsString, radix)` will try to parse integer in the beginning of string. For example, `parseInt('120px', 10)` will output 120. When parsing failed, it returns `NaN` instead. We connect an `'0'` to the beginning of each character so it will return `0` for any non numeric-alpha characters. And we can sort same letters together and non-alpha character to the beginning by this algorithm.
* After `sort` and `join`, `"Hello world!123"` would become `" !123deHllloorw"`. An matching against `/([a-z])\1*/ig` will ignore any non-alpha character and split the string into chunks with same letters. `.
* `map` convert `"aaa"` to `"3a"` as required in the question.
* The second sort use same function as the first one. Thanks to the number system, `"3b"` would be less than `"12a"` in base 36 just as we expect: It compare counts first (`n div 36`), and compare the letter later (`n mod 36`).
* Finally `join` them together.
---
# [JavaScript (Node.js)](https://nodejs.org), 146 bytes
```
f=(s,...a)=>(s=s.replace(/[^a-z]/ig,''))?f(s.replace(RegExp(s[c=0],'ig'),x=>(l=++c+x,'')),...a,l):a.sort((x,y)=>p(x,36)-p(y,36),p=parseInt).join``
```
[Try it online!](https://tio.run/##RY0/TwMhGId3PwUbLzmOqk0caqiLHYyLMW7nmb4ih7QECLwxV7/8Sbs4PcPz@3PAH6ym@Ex9TF92WSYNVSqlUOgtVF1VsTmgsbAaPrD/HVfeSc6FeJjg371at5sz1MHo61Fy77iQc@sH3XWmmy@Fy6gMYoOqpkIAszy1j9y4vhN9htOZMuuMpdqnSEIdko/7/UJ64M@ejkjsDaNLXDL@iISfWC17wUKefIq1yXo8u5vbNR/vr0hNqezQfAPprWmBFKwKyQGxjvH3yBsmICHE8gc "JavaScript (Node.js) – Try It Online")
[Answer]
# Java 10, ~~223~~ ~~209~~ 301 bytes
```
s->{int i=32,t;String M[]=new String[i],r,R="";for(var c:s)M[c%32]+=c>64&c<91|c>96&c<123?c:R;for(;i-->0;M[i]=(t=r.length()-4)>0?t+r.split(R)[t+3]:R)r=M[i]+R;java.util.Arrays.sort(M);for(var p:M)R+=p;return R;}
```
+92 bytes as a fix for inputs with more than 9 of a single letter.. Will see if I can bring that down again with a different approach.
[Try it online.](https://tio.run/##lVJRa9swEH7Pr7gZNiRsizQphcazu25921yG1zfXjIuiJEocyUiXlNDlt2dyMWMPXWH3IHTS932n@04bPGC6WWzPskXvoURtnkcA2pByS5QK7vsU4Ac5bVYgmVyjqxvwPAvnp1FYPCFpCfdgIIezT4vnwAadTycJZQOvrJvcqKdBptZN4pIqj6JsaR07oAM587ys5fvppIlzWVxdfpAfry9@yeL6KuwuJtMbOate0JlO02KclUEkZ5Q70SqzojXj6SUvxjcUO@G7VhOreE3xtJlV3OU9Oq6yTehW7Em34tY5PHrhrSNWJgyTOU@L/oWfj6QYG8fIhVNdGyy4bVsWPT7eRUkUcS6k3XXo1INlf8Pn/4Bz/qfFblbyKs67zCnaOwNVdjpnvYHdft4GAwcfD1YvYBfmwAazGkA@DOHoSe2E3ZPowhW1hhkhWfRV0xYJHtCsbCTIfgkzemmQ9fXfpN4h4Ry9gu/oSJO2xgcdv4VP734G1/9T7Zt9I/DVWHiwS6C1Ao87Ba2i8PNeLXsanc6/AQ)
**Explanation:**
```
s->{                        // Method with character-array parameter and String return-type
  int i=32,                 //  Index-integer, starting at 32
      t;                    //  Temp-integer, uninitialized
  String M[]=new String[i], //  Create a String-array of size 32, filled with null by default
         R="",              //  Result-String, starting empty
         r;                 //  Temp-String, uninitialized
  for(var c:s)              //  Loop over the characters of the input-array:
    M[c%32]+=               //   Append the string at index code-point of `c` modulo-32 with:
     c>64&c<91|c>96&c<123?  //    If the character is a letter:
      c                     //     Append the character
     :                      //    Else:
      R;                    //     Append an empty String
  for(;i-->0                //  Loop `i` in the range (32, 0]:
      ;                     //    After every iteration:
       M[i]=                //     Replace the String at index `i` with:
        (t=r.length()-4)    //      Set `t` to the length of String `r` minus 4
                            //      (the minus 4 is for the prepended "null")
         >0?                //      If this length minus 4 is larger than 0:
          t                 //       Set the String to this length minus 4
          +r.split(R)[t+3]  //       Appended with the last character of `r` as String
         :                  //      Else:
          R)                //       Make the String at index `i` empty
    r=M[i]                  //   Set `r` to the `i`'th String
          +R;               //  Converted to String
                            // (null becomes "null", to prevent NullPointerException-errors)
  java.util.Arrays.sort(M,  //  Now sort the array of Strings on:
   (a,b)->                  //   For each pair of two Strings:
     new Byte(              //    Convert the first String to a number
      (0+a).replaceAll("\\D",""))
                            //    after we've added a leading 0 and removed all non-digits
    .compareTo(             //   And compare it to:
     new Byte(              //    The second String converted to a number
      (0+b).replaceAll("\\D",""))));
                            //    after we've added a leading 0 and remove all non-digits
  for(var p:M)              //  Loop over the Strings of the array:
    R+=p;                   //   And append each to the result-String `R`
  return R;}                //  And finally return the result-String `R`
```
[Answer]
# [Swift 4.2.1/Xcode 10.1](https://developer.apple.com/swift/), ~~1054~~ ~~1050~~ ~~1048~~ ~~370~~ ~~368~~ 364 bytes
```
s.map{String($0)}.filter{$0.rangeOfCharacter(from:.letters) != nil}.reversed().reduce(into:[String:Int]()){d,s in if let l=[s.uppercased(),s.lowercased()].first(where:{d[$0] != nil}){d[l]=d[l]!+1}else{d[s]=1}}.sorted{let c=$0.value-$1.value;return c==0 ?$0.key.compare($1.key,options:.caseInsensitive) == .orderedAscending:c<0}.map{"\($0.value)\($0.key)"}.joined()
```
[Try it online!](https://tio.run/##fVE9T8MwEN35FUfVwRbFSiWmQEAIhIQYQIKtZDDxpZimduS7tEJRfnu5tMCEWKx3X@/ePdPW13y28@s2Joa72AVn2cdwVHehgiUGTJbxyRJtY3KKcnjm5MNSw@nlN4QeEnKXwo7M2rb9IaummR5M7RvG1E8zk2xY4mN9826TrSSn6hTXuWmQJSANxwUE3wwm4UZidEoLdF2FygeO@eLAmt8HLpXWvZsR@AC@BmGApliQ6doWU2X3szMyTdz@hqUIScRq@44J894tpln5s1G4Fk1ZjM/xyXzAhlAyVBbzYTAkrqDrxx1VIVdsbNPh6XR@AOeHu6VUZHAl5RV@miquW5tQSZOEs9iOdlJuRin3gTCQZ79BDUUBRjwVRe6aKgxuvK@6yIa9i5NX9bNP76GQ6clgPqIP40m74agVR1j99UeTB88ry/AipseJ1v@13lq2b6INnmxivxcrc7SSsd0X "Swift 4 – Try It Online")
@KevinCruijssen also removed some spaces.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 30 bytes
```
Ｆ⌈Ｅβ№↧θιＦβ¿⁼№↧θκ⊕ι⁺⊕ι§Φθ⁼↧λκ±¹
```
[Try it online!](https://tio.run/##bY7PCsIwDIfvPkWOGdSDZ0/iHxio7OALZFumZV3r2lT39rUOQQQDye@QLx9pbuQbRyalznnAE016iEPOO9YKti5awaN7sm8oMI6FAl3kgpmuC9Ad4H6MZAL@g/vcpW08D2yFW3wfQ@V1BisTA/7uFGyktC1PeNBG2OOo4CP/as2szePMVxLG1fufdUo7EqozABV50aKdDXCh0C/S8mHoBQ "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｆ⌈Ｅβ№↧θι
```
Run through the lowercase alphabet and find the highest character count in the lowercased input. Loop over the implicit range. (The loop actually goes from `0` to `n-1` so I have to increment the loop variable at each use.)
```
Ｆβ
```
Loop over the lowercase alphabet again.
```
¿⁼№↧θκ⊕ι
```
If the count of the current letter is equal to the outer loop value...
```
⁺⊕ι§Φθ⁼↧λκ±¹
```
Concatenate the current count with the last occurrence of the current letter and implicitly print.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
fØẠŒuL,ṪƊƙ$ŒuÞ
```
[Try it online!](https://tio.run/##y0rNyan8/z/t8IyHuxYcnVTqo/Nw56pjXcdmqgA5h@f9///fJbEkMSmxOFUhILGoJLMkMz@vWCEksTgbAA "Jelly – Try It Online")
Full program.
[Answer]
## NodeJS, 299 bytes, -6 bytes thank to @tsh
Not so beauty but it work!
```
(x,l={},g=p=>p.charCodeAt(),q=p=>p.toLowerCase())=>Object.entries([...x[R='replace'](/[^a-z]/gi,'')].reduce((m,n)=>(r=q(n),l[r]=g(n)>96?1:0,{...m,[r]:-~m[r]}),{})).sort((a,b)=>a[1]^b[1]?a[1]-b[1]:g(q(a[0]))-g(q(b[0]))).map(([m,n])=>[n,m]).join``[R](/,/g,'')[R](/[a-z]/g,v=>l[v]?q(v):v.toUpperCase())
```
## Javascript (ES8) (Firefox or Chrome), 294 bytes, -1 byte thank to @tsh
With new `.flat` method, I can save 10 bytes:
```
(x,l={},g=p=>p.charCodeAt(),q=p=>p.toLowerCase())=>Object.entries([...x[R='replace'](/[^a-z]/gi,'')].reduce((m,n)=>(r=q(n),l[r]=g(n)>96?1:0,{...m,[r]:-~m[r]}),{})).sort((a,b)=>a[1]^b[1]?a[1]-b[1]:g(q(a[0]))-g(q(b[0]))).map(([m,n])=>[n,m]).flat().join``[R](/[a-z]/g,v=>l[v]?q(v):v.toUpperCase())
```
Try this online:
<https://repl.it/repls/ConcernedHorribleHypothesis>
[Answer]
# [R](https://www.r-project.org/), ~~131~~ 129 bytes
```
cat(paste0(N<-by(X<-utf8ToInt(gsub('[^a-z]','',scan(,''),T)),G<-X%%32,length),L<-intToUtf8(by(X,G,tail,1),T))[order(N,L)],sep='')
```
[Try it online!](https://tio.run/##bY/NasMwEITvfoolIVgC2UR2Cz04t0AoDSEHFwJpCmtXdoWNZKQN6Q99dtduqWmhexzmm5l1/RwuDjvwJRomwpCDNoBQnU1J2hogC9i29gIKvVYOSHnSpg6q1Y@F0Qvx95HPokmL45gPel8isQ49qSXbZVHxyg5ZdKbqJre3hljtzwULj48YvZ3CoVxMK0TOudhk0WGxSBPRKlPTMxfbLNKGcns/JLAxTGwEoW6F/AKO1j0px3Ziy0/Cq241BPUfQVCx2Z2mBglyNLWdcZiDrKWWRtoEkybNg3Fn@GBCPprXSFigV7BHR3r8xw@kb77BQq6lks0Iy710iU79VX6NfyN@9033T7Fc2v4T "R – Try It Online")
[Answer]
# [Julia 1.0](http://julialang.org/), 158 bytes
```
¬t=(c=Dict();C=Dict();for i=eachmatch(r"\w",t);l=i.match;k=lowercase(l);c[k]=get(c,k,0)+1;C[k]=l;end;*(["$v$(C[k])" for (v,k)=sort([(v,k) for (k,v)=c])]...))
```
Original ungolfed version with same logic:
```
function password(text)
    letter_counts = Dict()
    cases = Dict()
    for i in eachmatch(r"\w", text)
        letter = i.match[1]
        letter_key = lowercase(letter)
        letter_counts[letter_key] = get(letter_counts, letter_key, 0) + 1
        cases[letter_key] = letter
    end
    sorted_counts = sort([(value, key) for (key, value) in letter_counts])
    return string(["$v$(cases[k])" for (v,k) in sorted_counts]...)
end
```
[Try it online!](https://tio.run/##VY4xDsIwEAR7XhFZFHdgRVBbrqCjoaALKQ5jwNjYyDkCj@IVfCwkIAq61exotedbcDR/dN3ryRqMXjrDgGrxC4eUC6ctmdOF2Jwgi@1dSEYVtCs/SHkd0t1mQ42FgMpUvtZHy2CklzOcztViIEHZuFcTqMS4HcOAUBTDOrTSo25SZqg@@Uu9bFGbGuuyLBG70TW7yCHC6wli5dgTFxuKxyQQ/7olMe36K8WaMjt2KTa92Pje694 "Julia 1.0 – Try It Online")
[Answer]
# Perl 6, ~~86~~ 82 bytes
```
{[~] flat map *[0,2],sort map {+$^b,$^a,$b[*-1]},kv classify &lc,.comb: /<alpha>/}
```
[Answer]
## Rebol, 149, 146 bytes
```
f: func[s][l: charset[#"a"- #"z"#"A"- #"Z"]rejoin sort/skip collect[parse sort s[any[copy t[copy o l any o](keep length? t keep last t)| skip]]]2]
```
[Try it online!](https://tio.run/##TY1BSwQxDIXv@yueGQ8qLOLqaS8iePMi4slSIVM6s2VKU5p4WPG/jzO7IF5e8j5e8lrsJc9vq8L5edhj@CrBqXd5j3DgptFcR0xbdPRNHT2dtg/yJlu1lsoIlWa3OqWKIDnHYK6udycOdVyOLkg9ws5DkLEwiL@aYqzIsYx2eIThbFkNdv2D9aP3fuc3c23SRwygl2QTG965jEKbP/zMxj0vla/cLFmSoktGp3@Ru93lzf3D5wXNvw)
Ungolfed:
```
f: func [s] [
    l: charset[#"a" - #"z" #"A" - #"Z"]
    rejoin sort/skip collect [
        parse sort s [
            any [
                copy t [copy o l any o] (keep length? t keep last t)
                | skip
            ] 
        ]
    ] 2
]
```
Example usage in Rebol console:
```
>> f "Kitkat Tango"
== "1g1i1n1o2a2k3T"
>> f "Database Partitions Task"
== "1b1D1e1k1n1o1P1r2i3s4T5a"
>> f "12$*34^!"
== ""
```
]