I need help for complex data sort from database. Suppose my data stored in table like this:
Description
--------------
JCB Excavator - ECU P/N: 728/35700
Geo Prism 1995 GEO - ABS #16213899 GEO pump
Geo Prism 1995 - GEO ABS #16213897
Geo Prism 1995 - ABS #16213897
Ersatz Airbags, Gurtstrammer und Auto Körper Teile
this test JCB pipe & JCB pump
Wie man BBA reman erreicht
7 rows are there. I want to write a SQL query in such a way as a result it will sort data based on my input word. Suppose my search term is GEO,JCB
two words together separated by comma. The rows that will come first are those where search word found maximum time. So for GEO
the word has the maximum time in most of the rows.
Two sorts will be required:
- first sort data in such way where search term found maximum time.
- second sort data on the basis maximum occurrence of search term found in each rows.
Suppose GEO
the search term found in maximum row.
So all the rows that have GEO
keyword will come first and then JCB
related data will come.
In GEO
related data those rows will come first that have maximum GEO
keyword.
So the output will be look like.
Description
--------------
Geo Prism 1995 GEO - ABS #16213899 GEO pump
Geo Prism 1995 - GEO ABS #16213897
Geo Prism 1995 - ABS #16213897
this test JCB pipe & JCB pump
JCB Excavator - ECU P/N: 728/35700
Ersatz Airbags, Gurtstrammer und Auto Körper Teile
Wie man BBA reman erreicht
Please help me to construct this kind of sql which will work in all SQL Server version.