English 中文(简体)
Sqlite勋章
原标题:Order Result in Sqlite
  • 时间:2010-05-10 05:39:19
  •  标签:
  • sqlite

在MySQL中,我的计票人一样。

SELECT * , IF( `Word` =  sim , 1, IF( `Word` LIKE  sim% , 2, IF( `Word` LIKE  %sim , 4, 3 ) ) ) AS `sort`
FROM `dblist`
WHERE `Word` LIKE  %sim% 
ORDER BY `sort` , `Word`

这辆车在SQlite没有工作。 我想要这样做。

SELECT * FROM dblist where word like  sim  or word like  sim%  or word like  %sim%  or word like  %sim 

同等的模拟是一只手工艺品,模拟率为二倍,模拟率为百分数,而模拟为最后一刻。

目前,我可以像我的智慧一样。 如何改变q子,以决定结果?

最佳回答

您应使用而不是IF,因为后者得不到Kallite的支持。 你们需要:

SELECT
    *,
    CASE WHEN `Word` =  sim  THEN 1
         WHEN `Word` LIKE  sim%  THEN 2
         WHEN `Word` LIKE  %sim  THEN 4
         ELSE 3
    END `sort`
FROM `dblist`
WHERE `Word` LIKE  %sim% 
ORDER BY `sort` , `Word`
问题回答
SELECT * , case when `Word` =  sim  then 1 else case when `Word` LIKE  sim%  then 2 else case when `Word` LIKE  %sim  then 4 else 3 end end end as sort
FROM `dblist`
WHERE `Word` LIKE  %sim% 
ORDER BY `sort` , `Word




相关问题
sqlite3 is chopping/cutting/truncating my text columns

I have values being cut off and would like to display the full values. Sqlite3 -column -header locations.dbs " select n.namelist, f.state, t.state from names n left join locations l on l.id = n.id ...

Entity Framework with File-Based Database

I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...

Improve INSERT-per-second performance of SQLite

Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second! Background: We are using SQLite as part of a desktop ...

Metadata for columns in SQLite v2.8 (PHP5)

How can I get metadata / constraints (primary key and "null allowed" in particular) for each column in a SQLite v2.8 table using PHP5 (like mysql_fetch_field for MySql)? sqlite_fetch_column_types (OO:...

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签