易截截图软件、单文件、免安装、纯绿色、仅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


相关问答:

请教SQLSERVER的两个问题 - MS-SQL Server / 疑难问题

1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......

sql 问题 - MS-SQL Server / 基础类

需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......

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

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

关于SQL语句OR的问题 - Oracle / 高级技术

通过NAME字段条件查询一个数据表,假设我有100个姓名,有以下两个方法,
方法1:
把100个Name 组成一个SQL语句,比如 Select * from tmp_table where Name='张三' or Name ='李四' Or ...Or Name='第一百个姓名'
......

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

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

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