0


我有一个列名为“order”的表,它是“十进制”数据类型。我想知道如何按此列订购;因为它未能根据包含以下数据的列正确订购: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'而失败?如果不是,那么如何按十进制列数据类型正确排序?

提前致谢。

4

2 回答 2

4

从此:_

如果要使用关键字作为名称,则需要引用它。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
于 2013-09-24T08:46:22.543 回答
2

您通过按常量字符串('order')而不是列内容进行排序来破坏顺序。

使用反引号

 ORDER BY `order` 
于 2013-09-24T08:43:23.763 回答