Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am working with sqlite3/python .

I would like to order results by the number of occurence of %@% in text.

For exemple

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

The code could be something like this :

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

I am looking for someMagic if it exists :-)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted
SELECT LENGTH(text)-LENGTH(REPLACE(text,'@',''))as counting from table
ORDER BY counting DESC

SQL Fiddle

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.