我有一个列名为'order'的表,它是'decimal'数据类型。我想知道如何通过这个专栏订购;因为它根据包含以下数据的列而无法正确排序:
1.0,2.0,3.0 ....等
输出顺序类似于:2.0,6.0,5.0 ......等
我一直在使用以下查询:
SELECT DISTINCT * FROM <tablename> WHERE <whereclause> ORDER BY 'order' LIMIT 150
但由于它已失败,我也想知道order by是否失败,因为列名是'order'?如果没有,那么如何按十进制列数据类型正确排序?
提前致谢。
答案 0 :(得分:4)
来自this:
如果要使用关键字作为名称,则需要引用它。那里 有四种在SQLite中引用关键字的方法:
'keyword' A keyword in single quotes is a string literal. "keyword" A keyword in double-quotes is an identifier. [keyword] A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility. `keyword` A keyword enclosed in grave accents (ASCII code 96) is an identifier. This is not standard SQL. This quoting mechanism is used by MySQL and is included in SQLite for compatibility.
您可以使用[]查询。
SELECT DISTINCT * FROM <tablename> WHERE <whereclause> ORDER BY [order] LIMIT 150
答案 1 :(得分:2)
您通过按常量字符串('order')而不是列内容排序来销毁订单。
使用反引号
ORDER BY `order`