3

抱歉,如果这是一个愚蠢的问题,但我无法理解这一点。如果存在,我只想选择一个带有冒号的值,这个值是“县”。但是,我不确定我是否以正确的方式进行此操作?任何帮助将不胜感激。

SELECT pe.personname AS "Person Name", pe.street||','||pe.town||','||
    IF NOT EXISTS(SELECT pe.county FROM persons pe WHERE pe.county = '')
    THEN pe.county||','|| 
    ELSE
    END IF
 pe.postcode as "Persons Address"
 FROM persons pe

如果没有县,更新版本会输出多个逗号。

SELECT personname as "Person Name"
street||','||town||
   CASE county
   WHEN '' THEN ''
   ELSE ','||county
   END
||','||postcode as "Person Address"
from Suppliers;
4

3 回答 3

1

我已经为此而去了,但得到一个缺少关键字的错误:-

 SELECT personname AS "Person Name", 
   street || ',' || town || ',' ||
     CASE WHEN county > ''
     THEN county || ','
     ELSE ''
     END 
   || postcode AS "Person Address"
 FROM Persons
于 2012-11-21T18:43:26.207 回答
0

我想你的意思是用逗号。

SELECT pe.personname AS "Person Name", pe.street||','||pe.town||
  IF pe.county <> ''
  THEN ','||pe.county
  ELSE ''
  END IF
pe.postcode as "Persons Address"
FROM persons pe

它可能更干净,(你可能必须)这样做:

SELECT pe.personname AS "Person Name",
  IF pe.county <> ''
  THEN pe.street||','||pe.town||','||pe.county
  ELSE pe.street||','||pe.town
  END IF
pe.postcode as "Persons Address"
FROM persons pe
于 2012-11-20T22:10:33.987 回答
0

如果您尝试获取两列,第一列是人名,第二列是地址部分,我会:

    select pe.personname, pe.street || ',' || pe.town || ',' || 
(case county when not null then (county || ',') else '' end), postcode

使用 case 语句来评估县,如果有一个用 ',' 插入它,否则 ''

于 2012-11-20T22:14:06.910 回答