问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

俺是Sql业余,请教高手Sql库中两个表级联查询问题 ,急 !!!

发布网友 发布时间:2022-04-22 20:43

我来回答

4个回答

热心网友 时间:2022-04-13 11:01

建立如下函数,以解决全拼音的情况,

调用时用Select dbo.f_GetPy(汉字,分隔符)

以下是函数创建方法:
CREATE function f_GetPy(@str varchar(100),@separator varchar(10))
returns varchar(8000)
as
begin
declare @re varchar(8000)
--生成临时表
declare @t table(chr nchar(1) collate Chinese_PRC_CS_AS_KS_WS,py nvarchar(20))
insert into @t select'吖','a'
insert into @t select'厑','aes'
insert into @t select'哎','ai'
insert into @t select'安','an'
insert into @t select'肮','ang'
insert into @t select'凹','ao'
insert into @t select'八','ba'
insert into @t select'挀',''
insert into @t select'兡','ke'
insert into @t select'瓸','wa'
insert into @t select'扳','ban'
insert into @t select'邦','bang'
insert into @t select'勹','bao'
insert into @t select'萡','be'
insert into @t select'陂','bei'
insert into @t select'奔','ben'
insert into @t select'伻','beng'
insert into @t select'皀','bi'
insert into @t select'边','bian'
insert into @t select'辪','uu'
insert into @t select'灬','biao'
insert into @t select'憋','bie'
insert into @t select'汃','bin'
insert into @t select'冫','bing'
insert into @t select'癶','bo'
insert into @t select'峬','bu'
insert into @t select'嚓','ca'
insert into @t select'偲','cai'
insert into @t select'乲','cal'
insert into @t select'参','can'
insert into @t select'仓','cang'
insert into @t select'撡','cao'
insert into @t select'册','ce'
insert into @t select'膥','cen'
insert into @t select'噌','ceng'
insert into @t select'硛','ceok'
insert into @t select'岾','ceom'
insert into @t select'猠','ceon'
insert into @t select'乽','ceor'
insert into @t select'叉','cha'
insert into @t select'犲','chai'
insert into @t select'辿','chan'
insert into @t select'伥','chang'
insert into @t select'抄','chao'
insert into @t select'车','che'
insert into @t select'抻','chen'
insert into @t select'阷','cheng'
insert into @t select'吃','chi'
insert into @t select'充','chong'
insert into @t select'抽','chou'
insert into @t select'出','chu'
insert into @t select'膗','chuai'
insert into @t select'巛','chuan'
insert into @t select'刅','chuang'
insert into @t select'吹','chui'
insert into @t select'旾','chun'
insert into @t select'踔','chuo'
insert into @t select'呲','ci'
insert into @t select'嗭','cis'
insert into @t select'从','cong'
insert into @t select'凑','cou'
insert into @t select'粗','cu'
insert into @t select'氽','cuan'
insert into @t select'崔','cui'
insert into @t select'邨','cun'
insert into @t select'瑳','cuo'
insert into @t select'撮','chua'
insert into @t select'咑','da'
insert into @t select'呔','dai'
insert into @t select'丹','dan'
insert into @t select'当','dang'
insert into @t select'刀',''
insert into @t select'恴','de'
insert into @t select'揼','dem'
insert into @t select'扥','den'
insert into @t select'灯','deng'
insert into @t select'仾','di'
insert into @t select'嗲','dia'
insert into @t select'敁','dian'
insert into @t select'刁','diao'
insert into @t select'爹','die'
insert into @t select'哋','dei'
insert into @t select'嚸','dim'
insert into @t select'丁','ding'
insert into @t select'丢','diu'
insert into @t select'东','dong'
insert into @t select'吺','dou'
insert into @t select'剢',''
insert into @t select'专','an'
insert into @t select'叾','g'
insert into @t select'垖','i'
insert into @t select'吨','n'
insert into @t select'咄','o'
insert into @t select'妸','e'
insert into @t select'奀','en'
insert into @t select'鞥','eng'
insert into @t select'仒','eo'
insert into @t select'乻','eol'
insert into @t select'旕','eos'
insert into @t select'儿','er'
insert into @t select'发','fa'
insert into @t select'帆','fan'
insert into @t select'匚','fang'
insert into @t select'飞','fei'
insert into @t select'吩','fen'
insert into @t select'丰','feng'
insert into @t select'瓰','fenwa'
insert into @t select'覅','fiao'
insert into @t select'仏','fo'
insert into @t select'垺','fou'
insert into @t select'夫','fu'
insert into @t select'猤','fui'
insert into @t select'旮','ga'
insert into @t select'侅','gai'
insert into @t select'甘','gan'
insert into @t select'冈','gang'
insert into @t select'皋','gao'
insert into @t select'戈','ge'
insert into @t select'给','gei'
insert into @t select'根','gen'
insert into @t select'更','geng'
insert into @t select'啹','geu'
insert into @t select'喼','gib'
insert into @t select'嗰','go'
insert into @t select'工','gong'
insert into @t select'兝','gongfen'
insert into @t select'兣','gongli'
insert into @t select'勾','gou'
insert into @t select'估','gu'
insert into @t select'瓜','gua'
insert into @t select'乖','guai'
insert into @t select'关','guan'
insert into @t select'光','guang'
insert into @t select'归','gui'
insert into @t select'丨','gun'
insert into @t select'呙','guo'
insert into @t select'妎','ha'
insert into @t select'咍','hai'
insert into @t select'乤','hal'
insert into @t select'兯','han'
insert into @t select'魧','hang'
insert into @t select'茠','hao'
insert into @t select'兞','haoke'
insert into @t select'诃','he'
insert into @t select'黒','hei'
insert into @t select'拫','hen'
insert into @t select'亨','heng'
insert into @t select'囍','heui'
insert into @t select'乊','ho'
insert into @t select'乥','hol'
insert into @t select'叿','hong'
insert into @t select'齁','hou'
insert into @t select'乎','hu'
insert into @t select'花','hua'
insert into @t select'徊','huai'
insert into @t select'欢','huan'
insert into @t select'巟','huang'
insert into @t select'灰','hui'
insert into @t select'昏','hun'
insert into @t select'吙','huo'
insert into @t select'嚿','geo'
insert into @t select'夻','hwa'
insert into @t select'丌','ji'
insert into @t select'加','jia'
insert into @t select'嗧','jialun'
insert into @t select'戋','jian'
insert into @t select'江','jiang'
insert into @t select'艽','jiao'
insert into @t select'阶','jie'
insert into @t select'巾','jin'
insert into @t select'坕','jing'
insert into @t select'冂','jiong'
insert into @t select'丩','jiu'
insert into @t select'欍','jou'
insert into @t select'凥','ju'
insert into @t select'姢','juan'
insert into @t select'噘','jue'
insert into @t select'军','jun'
insert into @t select'咔','ka'
insert into @t select'开','kai'
insert into @t select'乫','kal'
insert into @t select'刊','kan'
insert into @t select'冚','hem'
insert into @t select'砊','kang'
insert into @t select'尻','kao'
insert into @t select'坷','ke'
insert into @t select'肎','ken'
insert into @t select'劥','keng'
insert into @t select'巪','keo'
insert into @t select'乬','keol'
insert into @t select'唟','keos'
insert into @t select'厼','keum'
insert into @t select'怾','ki'
insert into @t select'空','kong'
insert into @t select'廤','kos'
insert into @t select'抠','kou'
insert into @t select'扝','ku'
insert into @t select'夸','kua'
insert into @t select'蒯','kuai'
insert into @t select'宽','kuan'
insert into @t select'匡','kuang'
insert into @t select'亏','kui'
insert into @t select'坤','kun'
insert into @t select'拡','kuo'
insert into @t select'穒','kweok'
insert into @t select'垃','la'
insert into @t select'来','lai'
insert into @t select'兰','lan'
insert into @t select'啷','lang'
insert into @t select'捞','lao'
insert into @t select'仂','le'
insert into @t select'雷','lei'
insert into @t select'塄','leng'
insert into @t select'唎','li'
insert into @t select'俩','lia'
insert into @t select'嫾','lian'
insert into @t select'簗','liang'
insert into @t select'蹽','liao'
insert into @t select'毟','lie'
insert into @t select'厸','lin'
insert into @t select'伶','ling'
insert into @t select'溜','liu'
insert into @t select'瓼','liwa'
insert into @t select'囖','lo'
insert into @t select'龙','long'
insert into @t select'娄','lou'
insert into @t select'噜','lu'
insert into @t select'驴','lv'
insert into @t select'寽','lue'
insert into @t select'孪','luan'
insert into @t select'抡','lun'
insert into @t select'頱','luo'
insert into @t select'呣','m'
insert into @t select'妈','ma'
insert into @t select'遤','hweong'
insert into @t select'埋','mai'
insert into @t select'颟','man'
insert into @t select'牤','mang'
insert into @t select'匁','mangmi'
insert into @t select'猫','mao'
insert into @t select'唜','mas'
insert into @t select'庅','me'
insert into @t select'呅','mei'
insert into @t select'椚','men'
insert into @t select'掹','meng'
insert into @t select'踎','meo'
insert into @t select'眯','mi'
insert into @t select'宀','mian'
insert into @t select'喵','miao'
insert into @t select'乜','mie'
insert into @t select'瓱','miliklanm'
insert into @t select'民','min'
insert into @t select'冧','lem'
insert into @t select'名','ming'
insert into @t select'谬','miu'
insert into @t select'摸','mo'
insert into @t select'乮','mol'
insert into @t select'哞','mou'
insert into @t select'母','mu'
insert into @t select'旀','myeo'
insert into @t select'丆','myeon'
insert into @t select'椧','myeong'
insert into @t select'拏','na'
insert into @t select'腉','nai'
insert into @t select'囡','nan'
insert into @t select'囔','nang'
insert into @t select'乪','keg'
insert into @t select'孬','nao'
insert into @t select'疒','ne'
insert into @t select'娞','nei'
insert into @t select'焾','nem'
insert into @t select'嫩','nen'
insert into @t select'莻','neus'
insert into @t select'鈪','ngag'
insert into @t select'銰','ngai'
insert into @t select'啱','ngam'
insert into @t select'妮','ni'
insert into @t select'年','nian'
insert into @t select'娘','niang'
insert into @t select'茑','niao'
insert into @t select'捏','nie'
insert into @t select'脌','nin'
insert into @t select'宁','ning'
insert into @t select'牛','niu'
insert into @t select'农','nong'
insert into @t select'羺','nou'
insert into @t select'奴','nu'
insert into @t select'女','nv'
insert into @t select'疟','nue'
insert into @t select'疟','nve'
insert into @t select'奻','nuan'
insert into @t select'黁','nun'
insert into @t select'燶','nung'
insert into @t select'挪','nuo'
insert into @t select'筽','o'
insert into @t select'夞','oes'
insert into @t select'乯','ol'
insert into @t select'鞰','on'
insert into @t select'讴','ou'
insert into @t select'妑','pa'
insert into @t select'俳','pai'
insert into @t select'磗','pak'
insert into @t select'眅','pan'
insert into @t select'乓','pang'
insert into @t select'抛','pao'
insert into @t select'呸','pei'
insert into @t select'瓫','pen'
insert into @t select'匉','peng'
insert into @t select'浌','peol'
insert into @t select'巼','phas'
insert into @t select'闏','phdeng'
insert into @t select'乶','phoi'
insert into @t select'喸','phos'
insert into @t select'丕','pi'
insert into @t select'囨','pian'
insert into @t select'缥','piao'
insert into @t select'氕','pie'
insert into @t select'丿','pianpang'
insert into @t select'姘','pin'
insert into @t select'乒','ping'
insert into @t select'钋','po'
insert into @t select'剖','pou'
insert into @t select'哣','deo'
insert into @t select'兺','ppun'
insert into @t select'仆','pu'
insert into @t select'七','qi'
insert into @t select'掐','qia'
insert into @t select'千','qian'
insert into @t select'羌','qiang'
insert into @t select'兛','qianke'
insert into @t select'瓩','qianwa'
insert into @t select'悄','qiao'
insert into @t select'苆','qie'
insert into @t select'亲','qin'
insert into @t select'蠄','kem'
insert into @t select'氢','qing'
insert into @t select'銎','qiong'
insert into @t select'丘','qiu'
insert into @t select'曲','qu'
insert into @t select'迲','keop'
insert into @t select'峑','quan'
insert into @t select'蒛','que'
insert into @t select'夋','qun'
insert into @t select'亽','ra'
insert into @t select'囕','ram'
insert into @t select'呥','ran'
insert into @t select'穣','rang'
insert into @t select'荛','rao'
insert into @t select'惹','re'
insert into @t select'人','ren'
insert into @t select'扔','reng'
insert into @t select'日','ri'
insert into @t select'栄','rong'
insert into @t select'禸','rou'
insert into @t select'嶿','ru'
insert into @t select'撋','ruan'
insert into @t select'桵','rui'
insert into @t select'闰','run'
insert into @t select'叒','ruo'
insert into @t select'仨','sa'
insert into @t select'栍','saeng'
insert into @t select'毢','sai'
insert into @t select'虄','sal'
insert into @t select'三','san'
insert into @t select'桒','sang'
insert into @t select'掻','sao'
insert into @t select'色','se'
insert into @t select'裇','sed'
insert into @t select'聓','sei'
insert into @t select'森','sen'
insert into @t select'鬙','seng'
insert into @t select'閪','seo'
insert into @t select'縇','seon'
insert into @t select'杀','sha'
insert into @t select'筛','shai'
insert into @t select'山','shan'
insert into @t select'伤','shang'
insert into @t select'弰','shao'
insert into @t select'奢','she'
insert into @t select'申','shen'
insert into @t select'升','sheng'
insert into @t select'尸','shi'
insert into @t select'兙','shike'
insert into @t select'瓧','shiwa'
insert into @t select'収','shou'
insert into @t select'书','shu'
insert into @t select'刷','shua'
insert into @t select'摔','shuai'
insert into @t select'闩','shuan'
insert into @t select'双','shuang'
insert into @t select'谁','shei'
insert into @t select'脽','shui'
insert into @t select'吮','shun'
insert into @t select'哾','shuo'
insert into @t select'丝','si'
insert into @t select'螦','so'
insert into @t select'乺','sol'
insert into @t select'忪','song'
insert into @t select'凁','sou'
insert into @t select'苏','su'
insert into @t select'酸','suan'
insert into @t select'夊','sui'
insert into @t select'孙','sun'
insert into @t select'娑','suo'
insert into @t select'他','ta'
insert into @t select'襨','tae'
insert into @t select'囼','tai'
insert into @t select'坍','tan'
insert into @t select'铴','tang'
insert into @t select'仐','tao'
insert into @t select'畓','tap'
insert into @t select'忒','te'
insert into @t select'膯','teng'
insert into @t select'唞','teo'
insert into @t select'朰','teul'
insert into @t select'剔','ti'
insert into @t select'天','tian'
insert into @t select'旫','tiao'
insert into @t select'怗','tie'
insert into @t select'厅','ting'
insert into @t select'乭','tol'
insert into @t select'囲','tong'
insert into @t select'偷','tou'
insert into @t select'凸','tu'
insert into @t select'湍','tuan'
insert into @t select'推','tui'
insert into @t select'旽','tun'
insert into @t select'乇','tuo'
insert into @t select'屲','wa'
insert into @t select'歪','wai'
insert into @t select'乛','wan'
insert into @t select'尣','wang'
insert into @t select'危','wei'
insert into @t select'塭','wen'
insert into @t select'翁','weng'
insert into @t select'挝','wo'
insert into @t select'乌','wu'
insert into @t select'夕','xi'
insert into @t select'诶','ei'
insert into @t select'疨','xia'
insert into @t select'仙','xian'
insert into @t select'乡','xiang'
insert into @t select'灱','xiao'
insert into @t select'楔','xie'
insert into @t select'心','xin'
insert into @t select'星','xing'
insert into @t select'凶','xiong'
insert into @t select'休','xiu'
insert into @t select'旴','xu'
insert into @t select'昍','xuan'
insert into @t select'疶','xue'
insert into @t select'坃','xun'
insert into @t select'丫','ya'
insert into @t select'咽','yan'
insert into @t select'欕','eom'
insert into @t select'央','yang'
insert into @t select'吆','yao'
insert into @t select'椰','ye'
insert into @t select'膶','yen'
insert into @t select'一','yi'
insert into @t select'乁','i'
insert into @t select'乚','yin'
insert into @t select'应','ying'
insert into @t select'哟','yo'
insert into @t select'佣','yong'
insert into @t select'优','you'
insert into @t select'迂','yu'
insert into @t select'囦','yuan'
insert into @t select'曰','yue'
insert into @t select'蒀','yun'
insert into @t select'帀','za'
insert into @t select'灾','zai'
insert into @t select'兂','zan'
insert into @t select'牂','zang'
insert into @t select'遭','zao'
insert into @t select'啫','ze'
insert into @t select'贼','zei'
insert into @t select'怎','zen'
insert into @t select'曽','zeng'
insert into @t select'吒','zha'
insert into @t select'甴','gad'
insert into @t select'夈','zhai'
insert into @t select'毡','zhan'
insert into @t select'张','zhang'
insert into @t select'钊','zhao'
insert into @t select'蜇','zhe'
insert into @t select'贞','zhen'
insert into @t select'凧','zheng'
insert into @t select'之',''
insert into @t select'中','zhong'
insert into @t select'州','zhou'
insert into @t select'劯','zhu'
insert into @t select'抓','zhua'
insert into @t select'专','zhuan'
insert into @t select'转','zhuai'
insert into @t select'妆','zhuang'
insert into @t select'骓','zhui'
insert into @t select'宒','zhun'
insert into @t select'卓','zhuo'
insert into @t select'孜','zi'
insert into @t select'唨','zo'
insert into @t select'宗','zong'
insert into @t select'棸','zou'
insert into @t select'哫','zu'
insert into @t select'劗','zuan'
insert into @t select'厜','zui'
insert into @t select'尊','zun'
insert into @t select'昨','zuo'

declare @strlen int
select @strlen=len(@str),@re=''
while @strlen>0
begin
select top 1 @re=UPPER(substring(py,1,1) )+substring(py,2,len(py))+@separator+@re,@strlen=@strlen-1
from @t a where chr<=substring(@str,@strlen,1)
order by chr collate Chinese_PRC_CS_AS_KS_WS desc
if @@rowcount=0
select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1
end
return(@re)
end

------------------------------------------

下一步就直接建立视图就可以了

Create View View_C

as

Select id,pname,jp,dbo.f_GetPy(pname,'') as p,dbo.f_GetPy(pname,' ') as fp

From TableA

热心网友 时间:2022-04-13 12:19

create view C
as
select A.id,A.pname,A.jp,B.p,B.fp
from A,B
where A.id=B.id

C是视图,在A中插入时C中就会插入了

热心网友 时间:2022-04-13 13:54

1.请将你的表的所有字段列出来
2.问题中的第二个是需要用触发器的,因为你是自动执行的嘛

热心网友 时间:2022-04-13 15:45

create table tba (id int,name varchar(10))

create table tbb(id int,keyy varchar(10),p varchar(10),j varchar(10))

insert into tba select 1,'黄金'
union all select 2,'白银'
union all select 3,'铁'
union all select 4,'木头'
union all select 5,'其他资源'

insert into tbb select 1,'黄','h','huang'
union all select 2,'金','j','jin'
union all select 3,'白','b',''
union all select 4,'银','y','yin'
union all select 5,'铁','t','tie'

--比较字符串函数
CREATE FUNCTION dbo.f_CompareSTR(

@s1 varchar(8000), --要比较的第一个字符串

@s2 varchar(8000), --要比较的第二个字符串

@split varchar(10) --数据分隔符

)RETURNS bit

AS

BEGIN

DECLARE @splitlen int

SET @splitlen=LEN(@split+'a')-2

WHILE CHARINDEX(@split,@s1)>0

BEGIN

IF CHARINDEX(@split+LEFT(@s1,CHARINDEX(@split,@s1)-1)+@split,@split+@s2+@split)>0

RETURN(1)

SET @s1=STUFF(@s1,1,CHARINDEX(@split,@s1)+@splitlen,'')

END

RETURN(CASE WHEN CHARINDEX(@split+@s1+@split,@split+@s2+@split)>0 THEN 1 ELSE 0 END)

END

--合并p的函数
CREATE FUNCTION dbo.f_strp(@col1 varchar(10))

RETURNS varchar(100)

AS

BEGIN

DECLARE @re varchar(100)

SET @re=''

SELECT @re=@re+p

FROM (select a.id,name,p,j from tba a,tbb b where dbo.f_CompareSTR(b.keyy,a.name,'')=1) as tb

WHERE id=@col1

RETURN @re

END

GO

--合并j函数
CREATE FUNCTION dbo.f_strj(@col1 varchar(10))

RETURNS varchar(100)

AS

BEGIN

DECLARE @re varchar(100)

SET @re=''

SELECT @re=@re+j

FROM (select a.id,name,p,j from tba a,tbb b where dbo.f_CompareSTR(b.keyy,a.name,'')=1) as tb

WHERE id=@col1

RETURN @re

END

GO

--查询
select id,name,p=dbo.f_strp(id),j=dbo.f_strj(id) from
(select a.id,name,p,j from tba a,tbb b where dbo.f_CompareSTR(b.keyy,a.name,'')=1) as a group by id,name
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
远得要命的爱情丁菲是谁演的 远的要命的爱情里的乔佳影是谁演的 远得要命的爱情乔佳影是什么角色 问。。我在厦门办的银行卡回江西可以用吗? 远得要命的爱情中的乔佳影是个怎样的人 厦门农信社的公告出来了,想问一下银行合同制和劳务派遣和正式工的区别... 厦门的信用社银联卡到南宁能不能用?要不要手续费? 泉州农信社年前新办的卡,存了钱,银行说三个工作日后才能动这个钱,为什 ... ...女鞋的话 是不是必须直通车 我们鞋子都是20---50鞋子利润低 直通车... 拼多多直通车200红包(拼多多直通车每天烧1000) 哥现在在徐汇区华泾路900号,想去虹泉路的韩国街,求往返路线,哥不打的,答者跪谢! 彩虹哥是什么意思 佛教电子书《蒙山施食念诵法仪》 蓝猫虹兔遇到一个小男孩小男孩的哥哥被坏人变坏了的电影叫什么 虹和哥已不再是当年的哥一样不再携秋水去揽星河回复这句号怎么回复_百度问一问 楞严咒是什么? 佛教说的 刹 罗刹 夜叉 是什么意思?? 虚空藏菩萨咒晚课怎么诵 简述商业银行的派生存款创造机制 银行存款可以理解为存款准备金和储户存入的钱(包括派生存款),可以这样理解吗 什么是商业银行的原始存款,派生存款和存款货币? 原始存款10000万元,法定存款准备金率10%,提现率5%,超额准备金率5%,试计算整个银行体系的派生存款。 原始存款,派生存款,存款货币的含义和关系 5.派生存款是怎样由存款货币银行体系创造出来的?并阐述“中央银行... 什么是存款派生机制 商业银行的派生存款是怎样形成的 是什么是派生存款额? 派生存款的意义? 派生存款都包括哪些 派生存款 西虹市首富,老哥能给个资源吗 法华经的全文 帮忙找一下这首歌,快手里面的,ID就是:虹哥很甜的哟 电脑网络连接有问题怎么办?黄色叹号和红叉怎么消除求解答? 剑气侠虹里,顾凌云的哥哥怎么死的 100个形声字? 日息怎么计算? 日息百分之三是怎么算利息 日息0.02%是日息多少钱,若依此算下去100万元一年利息多少钱? 日息计算成月息,年息,怎么计算的?麻烦有知识的朋友告知,谢谢 日息万分之3,相当于银行利息的多少? 借款2500,日息是0.065,一天的日息是多少 日息和月息区别大吗,比如10万,日息是万分之4.2一个月利息是多少,一年又... 800元0.05%日息是多少利息 10000元0.06的日息是多少? 利率怎么算?日息,月息.年息 月息3.125,日息是多么 借款1万,日息千分之三是多少,算不算高利贷,期限是50周,又是多少利息 月息12日息多少 你好,电脑上同时有ppt和pptx两种后缀名的文件,请问哪个是office2013版 ...