一道sql面试题解法
id strvalue type
1 how 1
2 are 1
3 you 1
4 fine 2
5 thank 2
6 you 2
要求用sql把它们搜索出来成为这样的
#how are you#fine thank you#
解答:
select
(select '#'+replace(
replace((SELECT strvalue FROM tb_test t where type = 1 FOR XML AUTO),'<t strvalue="',' ')
,'"/>', ' ')
+'#'
)
+
(select replace(replace((SELECT strvalue FROM tb_test t where type = 2 FOR XML AUTO),'<t strvalue="',' '),'"/>', ' ')+'#')
恋花望月轻轻唱 听雨随风悄悄追