3

在未规范化的表结构中,我需要为每个邮政编码选择第一个非空(长度!= 0 且非空)列。

表格布局(两列均为text):

| ZIP   | Contact | ...
| 69123 |         | 
| 69123 | WS      | 
| 54516 | null    | 
| 54516 | CS      | 
| 72226 | RH      | 
| 72226 | PH      | 

结果应如下所示:

| ZIP   | Contact | ...
| 69123 | WS      | 
| 54516 | CS      | 
| 72226 | RH      | 

像这样的东西:

SELECT ZIP, fristNotEmpty(Contact) 
FROM masterdata GROUP BY ZIP
4

1 回答 1

4
SELECT ZIP, 
       min(Contact)
FROM masterdata
where Contact is not null and length(Contact) > 0
GROUP BY ZIP
于 2012-11-10T14:08:02.750 回答