相同
我想按实际创建的列对结果进行分类
SELECT A, B, @MID(C,2,2) as X FROM foobar ORDER BY X DESC
我知道这可以在MySQL中工作,但它不能在SQL(SQLBase)中工作。
有什么建议吗?
我试过了:
SELECT A, B, @MID(C,2,2) as X FROM foobar ORDER BY @MID(C,2,2) DESC
结果是Invalid Columnname
与使用ORDER BY X
您也可以通过列ordinal
进行订购。但请记住,如果修改了查询,则需要检查ORDER BY
子句,以确保它在正确的列上排序。这应该对你有用:
SELECT A, B, @MID(C,2,2) as X
FROM foobar
ORDER BY 3 DESC
另一种选择是使用子查询:
SELECT A, B, X
FROM
(
SELECT A, B, @MID(C,2,2) as X
FROM foobar
) AS S
ORDER BY X DESC