S02053

错误代码

S02053

报错信息

The select clause with DISTINCT keyword must contain all ORDER BY columns RefId: S02053

错误原因

SQL 语句中带有 DISTINCT 关键字,且 order by 子句所包含的列未出现在 DISTINCT 中。

def createMyTable(n) {
    intv = take(1..10, n)
    symbol = take(`a`b`c, n)
    id = rand(100, n)
    strv = take("abs" + string(1..10), n)
    doublev = rand(10.0, n)
    return table(intv, strv, doublev, id, symbol)
}

n = 100
t = createMyTable(n)

select DISTINCT id from t order by intv; // 报错
select DISTINCT intv, id from t order by intv; // 正常

解决办法

将 order by 中所有出现列添加至 select 中。