Mysql

按文本中單詞出現次數排序結果

  • January 23, 2014

我正在使用 sqlite3/python 。

我想按 in 的出現次數對結果進行%@%排序text

舉個例子

Jimmy 10 // Jimmy wrote 10 strings like %@%
James 2
Sophia 0
..etc

程式碼可能是這樣的:

cursor = db.execute("SELECT name, text 
                      FROM MyTable
                     WHERE text LIKE '%@%'
                     ORDER BY someMagic DESC")

我正在尋找someMagic它是否存在:-)

SELECT LENGTH(text)-LENGTH(REPLACE(text,'@',''))as counting from table
ORDER BY counting DESC

SQL小提琴

引用自:https://dba.stackexchange.com/questions/57369