案例声明无效标识符

时间:2017-06-30 19:34:09

标签: sql

我现在处于度假的心情,只是无法用“无效的标识符”直接结束。有没有人在这里看到问题

SELECT       DATE,   ACCOUNT,  SOURCE,
CASE WHEN   SOURCE ='0' THEN "CHICAGO"
      WHEN   SOURCE ='1' THEN "NEW YORK"
      WHEN   SOURCE ='T' THEN "SSCHICAGO"
      WHEN   SOURCE ='S' THEN "SSNEW YORK"
      ELSE "UAT" END AS TYPEACC
      FROM CUSTOMER

      WHERE       DATE BETWEEN '01 DEC 2015' AND ' 31 DEC 2015'
      GROUP BY
            DATE,   ACCOUNT,   SOURCE, TYPEACC

2 个答案:

答案 0 :(得分:0)

以下SQL工作

SELECT DATE, ACCOUNT, SOURCE, 
CASE WHEN SOURCE ='0' THEN 'CHICAGO' 
WHEN SOURCE ='1' THEN 'NEW YORK' 
WHEN SOURCE ='T' THEN 'SSCHICAGO' 
WHEN SOURCE ='S' THEN 'SSNEW YORK' 
ELSE 'UAT' END AS TYPEACC FROM CUSTOMER 
WHERE DATE BETWEEN '01 DEC 2015' AND ' 31 DEC 2015

当我修改它以包含变量TYPEACC或case语句的group by时它不起作用。 IT将TYPEACC作为无效标识符抛出。我错过了什么? 提前谢谢。

SELECT DATE, ACCOUNT, SOURCE, 
CASE WHEN SOURCE ='0' THEN 'CHICAGO' 
WHEN SOURCE ='1' THEN 'NEW YORK' 
WHEN SOURCE ='T' THEN 'SSCHICAGO' 
WHEN SOURCE ='S' THEN 'SSNEW YORK' 
ELSE 'UAT' END AS TYPEACC FROM CUSTOMER 
WHERE DATE BETWEEN '01 DEC 2015' AND ' 31 DEC 2015

按日期,帐户,来源,TYPEACC分组

(OR)

SELECT DATE, ACCOUNT, SOURCE, 
CASE WHEN SOURCE ='0' THEN 'CHICAGO' 
WHEN SOURCE ='1' THEN 'NEW YORK' 
WHEN SOURCE ='T' THEN 'SSCHICAGO' 
WHEN SOURCE ='S' THEN 'SSNEW YORK' 
ELSE 'UAT' END AS TYPEACC FROM CUSTOMER 
WHERE DATE BETWEEN '01 DEC 2015' AND ' 31 DEC 2015
GROUP BY
DATE, ACCOUNT, SOURCE, 
CASE WHEN SOURCE ='0' THEN 'CHICAGO' 
WHEN SOURCE ='1' THEN 'NEW YORK' 
WHEN SOURCE ='T' THEN 'SSCHICAGO' 
WHEN SOURCE ='S' THEN 'SSNEW YORK' 
ELSE 'UAT' END AS TYPEACC

答案 1 :(得分:0)

这里有正确的格式:

SELECT DATE,
       ACCOUNT,
       SOURCE, 
       CASE SOURCE
           WHEN '0' THEN 'CHICAGO' 
           WHEN '1' THEN 'NEW YORK' 
           WHEN 'T' THEN 'SSCHICAGO' 
           WHEN 'S' THEN 'SSNEW YORK' 
           ELSE 'UAT'
           END AS TYPEACC
FROM CUSTOMER 
WHERE DATE BETWEEN '2015-12-01' AND '2015-12-31'
GROUP BY DATE, 
      ACCOUNT,
      SOURCE, 
      CASE SOURCE
           WHEN '0' THEN 'CHICAGO' 
           WHEN '1' THEN 'NEW YORK' 
           WHEN 'T' THEN 'SSCHICAGO' 
           WHEN 'S' THEN 'SSNEW YORK' 
           ELSE 'UAT'
           END

在结束日期之后,您也错过了单引号。我还为你修改了你的日期格式。你编码不多,是吗?