我已将 Company_Code
保存在 Company
表中,作为 char
数据类型。现在,我想将 Company_Code
作为 integer
数据类型检索为 DISTINCT
(没有值应该重复)并以 的形式>整数
数组。
我正在使用这个查询:
SELECT DISTINCT Company_Code
FROM Company
ORDER BY CAST(Company_Code AS INT);
此代码显示以下错误:
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
如果可能,请告诉我?
或者如果我做错了什么?
最佳答案
您可以将 DISTINCT
与 GROUP BY
交换:
SELECT Company_Code
FROM Company
GROUP BY Company_Code
ORDER By Cast(Company_Code as int);
-- if it is possible that CAST will fail, then you should use TRY_CAST
关于c# - 如何选择 Distinct char 数据类型并通过使用 sql 强制转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51901835/