SQL例

    技术2022-05-20  79

    设表有两列 id name 1 A 1 B 2 A 3 B 求 如果输入A,B则返回1,输入A则返回2,输入B则返回3

    declare @table table (id int,name varchar(1))insert into @tableselect 1,'A' union allselect 1,'B' union allselect 2,'A' union allselect 3,'B'declare @tj varchar(6);set @tj='A,B'if(charindex(',',@tj)>0)select max(id) from(select id from @table where name='A' union all select id from @table where name='B') aa group by id having(count(*)>1)elseselect max(id) from @table where name=@tj


    最新回复(0)