也许我把事情复杂化了..。
我只需要一个“简单”的查询来选择一列,但只返回不同的行。
关键是,如果它们相似,就需要排除它们,而不仅仅是完全匹配。
例如,下面是我当前的查询
select distinct channel from audio_srcs order by channel诀窍是这将返回如下所示的内容
Channel
--------
1001
1003
1003 <Description@unitid>
1004
1004 <Description@unitid>我希望显示1003行中唯一的一行,以及1004行中的一行(例如)。我不关心它返回哪一个。
我希望的最终结果如下所示:
Channel
---------
1001
1003
1004
etc.发布于 2012-06-15 23:28:58
SELECT distinct left(Channel, 4) as Channel -- or maybe first 5 characters
from audio_srcs
order by channel 发布于 2012-06-15 23:40:20
我会把分隔符作为区别。您只需要列中的第一个标记:
SELECT distinct left(Channel,
(case when charindex(' ', channel) <= 0 then len(channel)
else charindex(' ', channel)
end
)
) as Channel -- or maybe first 5 characters
from audio_srcs
order by channel 我使用了SQL Server版本的字符串函数。
https://stackoverflow.com/questions/11053669
复制相似问题