各位大侠救命,由于前辈建表的时候不合理,现在我不知如何解决
原SQL太长,简单的写了下SQL
如果能行转列的话就可以了
SQL="SELECT LINE,NAME1,N1,NAME2,N2,NAME3,N3 from TABLE"
希望得到结果
LINE NAME1 N1
LINE NAME2 N2
LINE NAME3 N3

解决方案 »

  1.   

    SELECT LINE,NAME1,N1 from TABLE union all
    select LINE,NAME2,N2 from TABLE union all select LINE, NAME3,N3 from TABLE
    go
      

  2.   


    SELECT LINE,NAME1,N1 
    UNION ALL
    SELECT LINE,NAME2,N2
    UNION ALL
    SELECT LINE,NAME3,N3
      

  3.   

    SELECT LINE,NAME1,N1,NAME2,N2,NAME3,N3 from TABLE
    -->
    SELECT LINE,NAME1,N1 from TABLE
    UNION ALL
    SELECT LINE,NAME2,N2 from TABLE
    UNION ALL
    SELECT LINE,NAME3,N3 from TABLE
    --是这意思?
      

  4.   

    SELECT LINE,NAME1,N1 
    UNION ALL
    SELECT LINE,NAME2,N2
    UNION ALL
    SELECT LINE,NAME3,N3
      

  5.   

    上面漏写了SELECT LINE,NAME1,N1 FROM TABLE1
    UNION ALL
    SELECT LINE,NAME2,N2 FROM TABLE1
    UNION ALL
    SELECT LINE,NAME3,N3 FROM TABLE1
      

  6.   

    行转列--union all
    列转行--join
      

  7.   

    行列互轉例子
    http://topic.csdn.net/u/20080614/17/22e73f33-f071-46dc-b9bf-321204b1656f.html
      

  8.   

    00001 ,1,2,3,4,5,6,7,8,9,10,0,12,13,14,15,0, 内轮内孔不良,花鼓螺纹不良,花鼓外观不良, 防尘盖铆接不良,轴螺纹不良,CONE螺纹不良,NUT螺纹不良,内轮跳动不良,外轮跳动不良,间隙跳动不良,右盘跳动不良,外轮纵跳不良,右盘横跳不良,,摩擦不良 轴跳动不良,未使用以上是查出来的一条记录,1---对应 内轮内孔不良,2---对应花鼓螺纹不良。
    说到底是前面的表没有建好
    我现在想要一条记录里面各种不良排行,如果是0就不显示
      

  9.   

    CREATE OR REPLACE FORCE VIEW "LINELEADER"."V_GETIOUNITINFO" ("LOTCODE", "N1", "N2", "N3", "N4", "N5", "N6", "N7", "N8", "N9", "N10", "N11", "N12", "N13", "N14", "N15", "N16", "BIT1NGNAME", "BIT2NGNAME", "BIT3NGNAME", "BIT4NGNAME", "BIT5NGNAME", "BIT6NGNAME", "BIT7NGNAME", "BIT8NGNAME", "BIT9NGNAME", "BIT10NGNAME", "BIT11NGNAME", "BIT12NGNAME", "BIT13NGNAME", "BIT14NGNAME", "BIT15NGNAME", "BIT16NGNAME")
    AS
      SELECT a.lotcode,
        a.ngpc6 n1,
        a.ngpc7 n2,
        a.ngpc8 n3,
        a.ngpc9 n4,
        a.ngpc10 n5,
        a.ngpc11 n6,
        a.ngpc12 n7,
        a.ngpc13 n8,
        a.ngpc14 n9,
        a.ngpc15 n10,
        a.ngpc16 n11,
        a.ngpc17 n12,
        a.ngpc18 n13,
        a.ngpc19 n14,
        a.ngpc20 n15,
        a.ngpc21 n16,
        b.bit1ngname,
        b.bit2ngname,
        b.bit3ngname,
        b.bit4ngname,
        b.bit5ngname,
        b.bit6ngname,
        b.bit7ngname,
        b.bit8ngname,
        b.bit9ngname,
        b.bit10ngname,
        b.bit11ngname,
        b.bit12ngname,
        b.bit13ngname,
        b.bit14ngname,
        b.bit15ngname,
        b.bit16ngname
      FROM lot_result_table a,
        iounit_table b,
        line_layout_config c,
        lot_table d
      WHERE a.lotcode   =d.lotcode
      AND b.unitid      =c.iounit_id1
      AND c.linecode    =d.linecode
      AND c.iounit_id1 IN ('6B','6A','69','68','67','66','65','64','18','16','15','14')
      UNION
      SELECT a.lotcode,
        a.ngpc22 n1,
        a.ngpc23 n2,
        a.ngpc24 n3,
        a.ngpc25 n4,
        a.ngpc26 n5,
        a.ngpc27 n6,
        a.ngpc28 n7,
        a.ngpc29 n8,
        a.ngpc30 n9,
        a.ngpc31 n10,
        a.ngpc32 n11,
        a.ngpc33 n12,
        a.ngpc34 n13,
        a.ngpc35 n14,
        a.ngpc36 n15,
        a.ngpc37 n16,
        b.bit1ngname,
        b.bit2ngname,
        b.bit3ngname,
        b.bit4ngname,
        b.bit5ngname,
        b.bit6ngname,
        b.bit7ngname,
        b.bit8ngname,
        b.bit9ngname,
        b.bit10ngname,
        b.bit11ngname,
        b.bit12ngname,
        b.bit13ngname,
        b.bit14ngname,
        b.bit15ngname,
        b.bit16ngname
      FROM lot_result_table a,
        iounit_table b,
        line_layout_config c,
        lot_table d
      WHERE a.lotcode   =d.lotcode
      AND b.unitid      =c.iounit_id2
      AND c.linecode    =d.linecode
      AND c.iounit_id2 IN ('19','17','1A')
      UNION
      SELECT a.lotcode,
        a.ngpc38 n1,
        a.ngpc39 n2,
        a.ngpc40 n3,
        a.ngpc41 n4,
        a.ngpc42 n5,
        a.ngpc43 n6,
        a.ngpc44 n7,
        a.ngpc45 n8,
        a.ngpc46 n9,
        a.ngpc47 n10,
        a.ngpc48 n11,
        a.ngpc49 n12,
        a.ngpc50 n13,
        a.ngpc51 n14,
        a.ngpc52 n15,
        a.ngpc53 n16,
        b.bit1ngname,
        b.bit2ngname,
        b.bit3ngname,
        b.bit4ngname,
        b.bit5ngname,
        b.bit6ngname,
        b.bit7ngname,
        b.bit8ngname,
        b.bit9ngname,
        b.bit10ngname,
        b.bit11ngname,
        b.bit12ngname,
        b.bit13ngname,
        b.bit14ngname,
        b.bit15ngname,
        b.bit16ngname
      FROM lot_result_table a,
        iounit_table b,
        line_layout_config c,
        lot_table d
      WHERE a.lotcode   =d.lotcode
      AND b.unitid      =c.iounit_id3
      AND c.linecode    =d.linecode
      AND c.iounit_id3 IN ('1B');第一次发帖,不知道这样贴是否可以
      

  10.   

    CREATE OR REPLACE ORACLE的 建议去ORACLE问问才最合适。
      

  11.   

    ORACLE的 建议去ORACLE问问才最合适。