各位大侠救命,由于前辈建表的时候不合理,现在我不知如何解决
原SQL太长,简单的写了下SQL
如果能行转列的话就可以了
SQL="SELECT LINE,NAME1,N1,NAME2,N2,NAME3,N3 from TABLE"
希望得到结果
LINE NAME1 N1
LINE NAME2 N2
LINE NAME3 N3
原SQL太长,简单的写了下SQL
如果能行转列的话就可以了
SQL="SELECT LINE,NAME1,N1,NAME2,N2,NAME3,N3 from TABLE"
希望得到结果
LINE NAME1 N1
LINE NAME2 N2
LINE NAME3 N3
select LINE,NAME2,N2 from TABLE union all select LINE, NAME3,N3 from TABLE
go
SELECT LINE,NAME1,N1
UNION ALL
SELECT LINE,NAME2,N2
UNION ALL
SELECT LINE,NAME3,N3
-->
SELECT LINE,NAME1,N1 from TABLE
UNION ALL
SELECT LINE,NAME2,N2 from TABLE
UNION ALL
SELECT LINE,NAME3,N3 from TABLE
--是这意思?
UNION ALL
SELECT LINE,NAME2,N2
UNION ALL
SELECT LINE,NAME3,N3
UNION ALL
SELECT LINE,NAME2,N2 FROM TABLE1
UNION ALL
SELECT LINE,NAME3,N3 FROM TABLE1
列转行--join
http://topic.csdn.net/u/20080614/17/22e73f33-f071-46dc-b9bf-321204b1656f.html
说到底是前面的表没有建好
我现在想要一条记录里面各种不良排行,如果是0就不显示
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');第一次发帖,不知道这样贴是否可以