易截截图软件、单文件、免安装、纯绿色、仅160KB

sql 简单查询求助 - MS-SQL Server / 疑难问题

数据内容

no name
-----------
x1 wade
2d james
pk kobe
aa KG


希望结果为


no name no name
-------------------------
x1 wade 2d james
px kobe aa KG



SQL code:
create table tb (no varchar(5),name varchar(10))
insert tb
select 'x1', 'wade' union all
select '2d', 'james' union all
select 'pk', 'kobe' union all
select 'aa', 'KG'

select max(no1) no ,max(name1) name,max(no2) no ,max(name2) name from
(
select (row_number()over(order by getdate())-1)/2 rn,
(case when row_number()over(order by getdate())%2=1 then no else '' end) no1,
(case when row_number()over(order by getdate())%2=1 then name else '' end) name1,
(case when row_number()over(order by getdate())%2=0 then no else '' end) no2,
(case when row_number()over(order by getdate())%2=0 then name else '' end) name2
from tb
) t
group by rn

/*
no name no name
----- ---------- ----- ----------
x1 wade 2d james
pk kobe aa KG

(所影响的行数为 2 行)

*/



具体里面有多少记录是未知的


学习中

引用
具体里面有多少记录是未知的

那些测试语句你不用管.只需要这3句:

select * , id=identity(int,1,1) into tmp from tb


相关问答:

求一个SQL语句 - MS-SQL Server / 基础类

字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......

sql语句问题 - MS-SQL Server / 疑难问题

现在有一个部门表dept(部门名称,部门号。。)有一个人员表emp(姓名,人员编号,职位,薪资,部门)
emp表中的内容是这样的:
a 1 工程师 3000 软件部
b 2 普通员工 2000 硬件部
c 3 工程师 4000 硬件部
d ......

关于Sql的问题 - .NET技术 / ASP.NET

将一个查询语句赋给一个变量,如下:
DECLARE @STR NVARCHAR(MAX)
SET @STR='SELECT * from SALE_PROD'
怎么样才能执行它呢?
请高手,仁兄,侠姐帮帮忙啊


多谢,可以啦,高手啊

直接执行就行了

exec ......

SQL语句 OR 存储过程? - .NET技术 / C#

执行数据库操作时,直接用SQL 语句好一些 还是用存储过程更佳呢?
各抒起见
这个的具体问题具体分析
简单的select 、update和insert当然sql解决了
复杂的放在sql服务端应该好点

楼主请参阅
http://msdn.micr ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号