SQL语句怎么把多个语句拼成一条?
答案:3 悬赏:20
解决时间 2021-03-29 20:09
- 提问者网友:雪舞兮
- 2021-03-29 02:32
SQL语句怎么把多个语句拼成一条?
最佳答案
- 二级知识专家网友:北方的南先生
- 2021-03-29 04:02
如果 a 和 b 结构一样 select a from tablename where b=1 union(unionall)select b from tablename where b=2;
如果结构不一样,但两者有关联的 column
select a.a , b.b from t1 a,t2 b where a.a=1 and b.b=2 and a.x=b.x;
如果结构不一样,且无关联的 column
那我就没招了
如果结构不一样,但两者有关联的 column
select a.a , b.b from t1 a,t2 b where a.a=1 and b.b=2 and a.x=b.x;
如果结构不一样,且无关联的 column
那我就没招了
全部回答
- 1楼网友:罪歌
- 2021-03-29 05:25
declare @sql varchar(8000)
set @sql=''
select @sql=@sql+','+a from tableName where b in (1,2,3)
set @sql=stuff(@sql,1,1,'')
select @sql
set @sql=''
select @sql=@sql+','+a from tableName where b in (1,2,3)
set @sql=stuff(@sql,1,1,'')
select @sql
- 2楼网友:行雁书
- 2021-03-29 04:27
select a from tablename where b=1
union
select b from tablename where b=2
union
select b from tablename where b=2
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯