求一句sql - MS-SQL Server / 疑难问题
表
a b
1 2
2 2
3 2
4 2
5 2
where b=2 查询后结果为
1,2,3,4,5
SQL code:
select stuff((select a from tb where b=2 order by a for xml path('')),1,1,'')
SQL code:
declare @s varchar(8000)
set @s=''
select @s=@s+a+',' from tb where b=2
SQL code:
declare @s varchar(100)
select @s=isnull(@s+',','')+ltrim(a)from tb where b=2
SQL code:
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
create table [tb]([a] int,[b] int)
go
insert [tb]
select 1,2 union all
select 2,2 union all
select 3,2 union all
select 4,2 union all
select 5,2
select stuff((select ','+ltrim(a) from tb where b = t.b for xml path('')),1,1,'' )
from [tb] t
where b = 2
group by b
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......