求助,case when 统一字段名
SELECT PGDWGMS.DWG_NO,
PGDWGMS.DWG_REV,
PGDWGMS.ISSE_NO,
(CASE
WHEN INSTR(UPPER(PGISSETR.TITLE_E), 'PM') >= 6 THEN SUBSTR(PGISSETR.TITLE_E,INSTR(UPPER(PGISSETR.TITLE_E), 'PM') - 6,12)
WHEN INSTR(UPPER(PGISSETR.TITLE_E), 'PM') < 6 AND INSTR(UPPER(PGISSETR.TITLE_E), 'PM') >= 1 THEN SUBSTR(PGISSETR.TITLE_E, 0, 12)
WHEN INSTR(UPPER(PGISSETR.TITLE_J), 'PM') >= 6 THEN SUBSTR(PGISSETR.TITLE_J,INSTR(UPPER(PGISSETR.TITLE_J), 'PM') - 6,12)
WHEN INSTR(UPPER(PGISSETR.TITLE_J), 'PM') < 6 AND INSTR(UPPER(PGISSETR.TITLE_J), 'PM') >= 1 THEN SUBSTR(PGISSETR.TITLE_J, 0, 12)
END)
FROM PGDWGMS, PGISSETR
...
如上sql执行完毕后
四个字段名为:DWG_NO,DWG_REV,ISSE_NO,INSTR(UPPER(PGISSETR
问题是:如何将第四个字段名自定义,注:不是自定义为四个,是一个,TKS
------最佳解决方案--------------------SELECT PGDWGMS.DWG_NO, PGDWGMS.DWG_REV, PGDWGMS.ISSE_NO, (CASE WHEN INSTR(UPPER(PGISSETR.TITLE_E), 'PM') >= 6 THEN SUBSTR(PGISSETR.TITLE_E,INSTR(UPPER(PGISSETR.TITLE_E), 'PM') - 6,12) WHEN INSTR(UPPER(PGISSETR.TITLE_E), 'PM') < 6 AND INSTR(UPPER(PGISSETR.TITLE_E), 'PM') >= 1 THEN SUBSTR(PGISSETR.TITLE_E, 0, 12) WHEN INSTR(UPPER(PGISSETR.TITLE_J), 'PM') >= 6 THEN SUBSTR(PGISSETR.TITLE_J,INSTR(UPPER(PGISSETR.TITLE_J), 'PM') - 6,12) WHEN INSTR(UPPER(PGISSETR.TITLE_J), 'PM') < 6 AND INSTR(UPPER(PGISSETR.TITLE_J), 'PM') >= 1 THEN SUBSTR(PGISSETR.TITLE_J, 0, 12) END) 第四个 FROM PGDWGMS, PGISSETR
------其他解决方案--------------------不是太理解哎,貌似这个SQL要取出来的就是4个字段吧。
如果是要对case when的这段定义一个字段名,在end)后面加一字段名即可。
------其他解决方案--------------------
正解,TKS
------其他解决方案--------------------SELECT PGDWGMS.DWG_NO,
PGDWGMS.DWG_REV,
PGDWGMS.ISSE_NO,
(CASE
WHEN INSTR(UPPER(PGISSETR.TITLE_E), 'PM') >= 6 THEN SUBS