一道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),'', ' ')
   +'#'
)
+
(select replace(replace((SELECT strvalue FROM tb_test t where type = 2 FOR XML AUTO),'', ' ')+'#')

 

转载于:https://www.cnblogs.com/superstar/archive/2009/10/30/1592911.html

你可能感兴趣的:(一道sql面试题解法)