sql的结果都是对称的,那有三角形的?

解决方案 »

  1.   

    假设sql server,假设姓名不重复,假设没有不男不女的,假设没有既男又女的:select c.name as '男',d.name as '女'
    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用一些数据测试一下,三角形也会出来的!
      

  2.   

    select a.xm 男,b.xm 女 from
    (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可以取出你想要的结果,不过有个假设:男人比女人多,再该动一下应该也可以适应女人多的情况。写的有些乱,不知能否看明白。
      

  3.   

    oracle:
     name ,sexselect  decode(sex,male,name,null)  man,
            decode(sex,female,name,null) woman
    from tname;
      

  4.   

    还得看情况,如果人数不一样多,还得填充null
      

  5.   

    这个问题新鲜,它叫做交差表查询,小弟早就搞定了,
      在ACCESS中要用到TRANSFORM和PIVOT关键字,不过用交差表查询向导非常容易搞定;
      在SQL SERVER中可以用CASE来判断;
      

  6.   

    select a.xm 男,
    (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多条记录。
    在执行效率上真是一个鲜明的对比呀!
      

  7.   

    select a.xm 男,
    (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多条记录,二者的执行效率真是对比鲜明呀!