如何在DB2中的select查询中修剪列的前三个字符?我试过下面的查询,但没有工作
SELECT
MIN(Column1),UPPER(RIGHT(Column2, LENGTH(Column2 - 3))) AS TEST
FROM TEST_TABLE
GROUP BY UPPER(Column2)
ORDER BY UPPER(Column2);
我得到了以下异常
The statement cannot be processed.
User response:
Correct the statement by including the expression in the GROUP BY clause
that are in the SELECT clause, HAVING clause, or ORDER BY clause or by
removing the column function from the SELECT statement.
sqlcode: -119
sqlstate: 42803
答案 0 :(得分:0)
你可以简单地使用substring函数来做同样的事情。
SELECT
MIN(Column1),substr(Column2,4) AS TEST
FROM TEST_TABLE
GROUP BY UPPER(substr(Column2,4))
ORDER BY UPPER(substr(Column2,4));
答案 1 :(得分:-1)
只是做:
SELECT
MIN(Column1),UPPER(substr(Column2, 4)) AS TEST
FROM TEST_TABLE
GROUP BY UPPER(substr(Column2, 4))
ORDER BY 2;