1.
table1 table2
id name nameid data
1 test 1 1234567
2 aaa 4 test1234
3 bbb
4 ccc如用用sql查询得到如下结果
id name data
1 test 1234567
2 aaa NULL
3 bbb NULL
4 ccc test1234
SQL查询语句如何写select table1.*,table2.data from table1 left join table2 on table1.id=table2.nameid2.
table1
id name
1 aaa
2 bbb
3 ccc
4 eee
.....
用SQL如何查询出的值为name的连接 如结果为
name
aaa,bbb,ccc,...declare @a varchar(8000)
set @a=''
select @a=@a+','+name from table1
select right(@a,len(@a)-1)
table1 table2
id name nameid data
1 test 1 1234567
2 aaa 4 test1234
3 bbb
4 ccc如用用sql查询得到如下结果
id name data
1 test 1234567
2 aaa NULL
3 bbb NULL
4 ccc test1234
SQL查询语句如何写select table1.*,table2.data from table1 left join table2 on table1.id=table2.nameid2.
table1
id name
1 aaa
2 bbb
3 ccc
4 eee
.....
用SQL如何查询出的值为name的连接 如结果为
name
aaa,bbb,ccc,...declare @a varchar(8000)
set @a=''
select @a=@a+','+name from table1
select right(@a,len(@a)-1)
解决方案 »
- 有没有什么办法吧sqlserver所有的表名查询出来啊
- 存储过程 like怎么使用阿?
- sql中有自动编码数据类型么?
- 请教高手,从一个数据库中插入到另一个数据库的的SQL语句
- 修改了Windows的Administrator密码,为什么服务管理器就启动不了了?
- 如和分组统计各总和?
- 初级问题:怎样对字段用distinct关键字?
- 我想把数据库中两张表的数据汇总后相减,写入第三张表中,这样的SQL语句怎么写啊?
- 如何SQL SERVER7.0中的企业管理器打开数据库中一个表中的记录?(急盼)
- 咨询死锁问题(deadlock)
- 如何比较日期,用DEPLHI的filter来写条件!急,在线等!!!
- 数据类型小问题
left join table2 as B on A.id = B.nameid
declare @i int
declare @m int
set @i = 1
select @m = max(id) from table1
set @a=''
while @i <= @m
begin
select @a = @a+','+name from table1 where id = @i
set @i = @i + 1
end
select @a
select a.*,b.data from table1 left join table2 b on a.id=b.nameid
2:
declare @a varchar(8000)
select @a=''
select @a=@a+name from table
select left(@a,len(@a)-1) as name