【发布时间】:2014-03-18 17:05:20
【问题描述】:
我有一个首字母缩写词和匹配词列表
acronym | word
---------------
FB | Facebook
FB | NULL
FB |
T | Twitter
R | NULL
F |
如果首字母缩写词有匹配的单词,则列出它。如果首字母缩写词没有匹配的单词,则用首字母缩写词填充第二列
例如:我想输出
FB | Facebook
T | Twitter
R | R
F | F
我编写了这个查询,加载时间很长,最终超时。我将如何实现预期结果?
select s1.acronym,
case
when s1.acronymnot in -- acronyms dont have a matching value
(select s2.acronym
from myTable s2
where word is not null and word !='')
then s1.acronym
else s1.word
end as 'word'
from myTable s1
where s1.acronym!=''
and s1.acronymis not null
【问题讨论】: