H
hetian_1982
Unregistered / Unconfirmed
GUEST, unregistred user!
现在我有一下表
表结构如下:
Style,color,qty1,qty2,qty3,qty4,qty5,desc1,desc2,desc3,desc4,desc5
表中的记录超过100000条!
现在我要将表的记录变成这样的结构进行查询
style,color,qty,desc
qty1对应desc1,qty2对应desc2........
例如:
表中某条记录为
Style ,color,qty1,qty2,qty3,qty4,qty5,desc1,desc2,desc3,desc4,desc5
A002 b01 2 3 4 5 0 aa bb cc dd ee
查询出来的结果是:
style, color, qty, desc
A002 b01 2 AA
A002 b01 3 BB
A002 b01 4 CC
A002 b01 5 DD
条件是:qty<>0
我现在的SQL语句是:
select * from (
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr1) as [3 size] from vewdwcop where qty1<>0
UNION
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr2) as [3 size] from vewdwcop where qty2<>0
UNION
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr3) as [3 size] from vewdwcop where qty3<>0
UNION
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr4) as [3 size] from vewdwcop where qty4<>0
UNION
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr5) as [3 size] from #vewdwcop where qty5<>0 ) aaa
但是这样的算法速度很慢,有没有更好更快的算法!!
大家帮帮忙!不会的帮顶一下!
表结构如下:
Style,color,qty1,qty2,qty3,qty4,qty5,desc1,desc2,desc3,desc4,desc5
表中的记录超过100000条!
现在我要将表的记录变成这样的结构进行查询
style,color,qty,desc
qty1对应desc1,qty2对应desc2........
例如:
表中某条记录为
Style ,color,qty1,qty2,qty3,qty4,qty5,desc1,desc2,desc3,desc4,desc5
A002 b01 2 3 4 5 0 aa bb cc dd ee
查询出来的结果是:
style, color, qty, desc
A002 b01 2 AA
A002 b01 3 BB
A002 b01 4 CC
A002 b01 5 DD
条件是:qty<>0
我现在的SQL语句是:
select * from (
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr1) as [3 size] from vewdwcop where qty1<>0
UNION
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr2) as [3 size] from vewdwcop where qty2<>0
UNION
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr3) as [3 size] from vewdwcop where qty3<>0
UNION
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr4) as [3 size] from vewdwcop where qty4<>0
UNION
select distinct Style as [1 Item Code],color as [2 color],UPPER(Descr5) as [3 size] from #vewdwcop where qty5<>0 ) aaa
但是这样的算法速度很慢,有没有更好更快的算法!!
大家帮帮忙!不会的帮顶一下!