sql的结果都是对称的,那有三角形的?
解决方案 »
- 一个很菜鸟的问题
- 这sql怎么写
- C#中语法错误,操作符丢失"
- 一对多表查询不重复显示怎么写
- 请问数据库的名字中含有空格 用sql语句查询时该怎么写?
- 如何将sql server 2000的数据库数据转换为sql server 2008?
- SQL Server 2005 Express Edition用代码怎么附加数据库
- 求一条SQL语句(单独为一的数据)
- 谁知道把SQL表里的简体数据转换成繁体字?
- 急需要帮助,谢谢了
- 从SQL MANAGER打开LOCAL数据库花时间比访问域中其它数据库长很多,为什么???
- 请问SQLSERVER中备份文件和备份到设备有什么不同?备份是为什么要新建备份设备,有什么用?
from
(select name,1+isnull((select count(*) from tablename where sex='男' and name <a.name ),0) as OrderNum from tablename where sex='男') as c
full join
(select name,1+isnull((select count(*) from tablename where sex='女' and name <a.name ),0) as OrderNum from tablename where sex='女') as d
on c.OrderNum=d.OrderNum用一些数据测试一下,三角形也会出来的!
(select rownum rn,xm from v_gbjbxx where xb='男') a,
(select rownum rn,xm from (
select xm from v_gbjbxx where xb='女'
union all
select null xm from v_gbjbxx
)where rownum <=(select count(*) from v_gbjbxx where xb='男')) b
where a.rn=b.rn我在ORACLE8上试过了,上面这个SQL可以取出你想要的结果,不过有个假设:男人比女人多,再该动一下应该也可以适应女人多的情况。写的有些乱,不知能否看明白。
name ,sexselect decode(sex,male,name,null) man,
decode(sex,female,name,null) woman
from tname;
在ACCESS中要用到TRANSFORM和PIVOT关键字,不过用交差表查询向导非常容易搞定;
在SQL SERVER中可以用CASE来判断;
(select xm from (select rownum rn,xm from v_gbjbxx where xb='女') where rn=a.rn) 女
from
(select rownum rn,xm from v_gbjbxx where xb='男')a这是我的另一种解法,结果和前一个完全一致,排列顺序也一样。
有意思的是前一个查询用时:0.161 s
这个用时:22.543 s
有500多条记录。
在执行效率上真是一个鲜明的对比呀!
(select xm from (select rownum rn,xm from v_gbjbxx where xb='女') where rn=a.rn) 女
from
(select rownum rn,xm from v_gbjbxx where xb='男')a
这是我的另一个解法,和前个结果完全一致,排列顺序也一样。
有意思的是,前一个用时:0.161 s
这个用时:22.543 s
共有500多条记录,二者的执行效率真是对比鲜明呀!