sql替换多个字符串
例如7.有三个表,如下TableUserInfoUserIDUserNameUserEmailUserTypeUserAddress===================...
例如7. 有三个表,如下
Table UserInfo
UserID UserName UserEmail UserType UserAddress
=====================================
1 Winder winder@gmail.com 1 3
2 David david@yahoo.com 3 1
7 Jimmy jimmy@sina.com 2
10 Simon simon@sina.com 2 9
11 Mary 5 4
12 Lily lily@abc.com 6 10
15 Lucy 1 4
19 Ender ender@yahoo.com 1
20 Alex alex@Yahoo.com 5 5
Table UserAddress
UserAddressID UserCountry UserAddress1 UserAdderss2 UserPhone
=========================================
1 US 1234567
3 China Zhejiang Huzhou 3698523
4 China
5 US CA 78897987
9 France Unknow
10 China Beijing
Table UserType
TypeID TypeName
============
1 Engineer
2 QA
3 Market
5 Manager
6 Counselor
8 Sales
============
现在有一种情况,需要在显示用户信息的时候把TypeName显示成另外的符号,并按新的UserType升序排序,如果有重复在按UserName升序排序,显示效果如下,请用一句SQL语句来实现。对应关系是Engineer-K,Manager-A,QA-S,Counselor-Z,Market-V,Sales-G。最终显示的UserType字段的内容是所属的TypeID和对应的符号合起来。
最后usertype的值类似1K,2S... 展开
Table UserInfo
UserID UserName UserEmail UserType UserAddress
=====================================
1 Winder winder@gmail.com 1 3
2 David david@yahoo.com 3 1
7 Jimmy jimmy@sina.com 2
10 Simon simon@sina.com 2 9
11 Mary 5 4
12 Lily lily@abc.com 6 10
15 Lucy 1 4
19 Ender ender@yahoo.com 1
20 Alex alex@Yahoo.com 5 5
Table UserAddress
UserAddressID UserCountry UserAddress1 UserAdderss2 UserPhone
=========================================
1 US 1234567
3 China Zhejiang Huzhou 3698523
4 China
5 US CA 78897987
9 France Unknow
10 China Beijing
Table UserType
TypeID TypeName
============
1 Engineer
2 QA
3 Market
5 Manager
6 Counselor
8 Sales
============
现在有一种情况,需要在显示用户信息的时候把TypeName显示成另外的符号,并按新的UserType升序排序,如果有重复在按UserName升序排序,显示效果如下,请用一句SQL语句来实现。对应关系是Engineer-K,Manager-A,QA-S,Counselor-Z,Market-V,Sales-G。最终显示的UserType字段的内容是所属的TypeID和对应的符号合起来。
最后usertype的值类似1K,2S... 展开
2个回答
展开全部
select UserID,UserName,UserEmail,(case when b.TypeName='Engineer' then UserType+'K' when b.TypeName='Manager' then UserType+'A' when b.TypeName='QA' then UserType+'S' when b.TypeName='Counselor' then UserType+'Z' when b.TypeName='Market' then UserType+'V' when b.TypeName='Sales' then UserType+'G' end) UserType,UserAddress
from UserInfo as a inner join UserType as b
on(a.UserType=b.TypeID)
order by UserType,UserName
from UserInfo as a inner join UserType as b
on(a.UserType=b.TypeID)
order by UserType,UserName
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询