日期:2014-05-18  浏览次数:20502 次

插入-查询语句---捆绕着我…help
A表:字段:c1,d1,cc1,cc2,cc3,cc4,cc5,dd1,dd2,dd3,dd4,dd5……hh1,hh2,hh3,hh4,hh5,a1,b1
B表:字段:   c1,d1,a1,b1,cc,dd,……hh

其中A表的cc1,cc2等这种字段
c1,d1,cc1,cc2,cc3,cc4,cc5,dd1,dd2,dd3,dd4,dd5……
-------------------------------------------------
1     a   10.2   5     null   null   null   5.2   4   null   null   null  
……
我想把A表插入到b   表里去,
c1,d1,a1,b1,cc,dd,……hh
---------------------------
1     a     go   to   10.2   5.2……
1     a     go   to         5       4……


这个样子的     语句怎么写??   不知道   看明白了没有。

------解决方案--------------------
具体对应不是很明白,大概

insert b(c1,d1,a1,b1,cc,dd,……hh)
select c1,d1,a1,b1,cc1,dd1,...hh1
from a
where not (cc1 is null and dd1 is null and ee1 is null and ... and hh1 is null)
union all
select c1,d1,a1,b1,cc2,dd2,...hh2
from a
where not (cc2 is null and dd2 is null and ee2 is null and ... and hh2 is null)
union all
...
union all
select c1,d1,a1,b1,cc5,dd5,...hh5
from a
where not (cc5 is null and dd5 is null and ee5 is null and ... and hh5 is null)


------解决方案--------------------
其中
where not (cc1 is null and dd1 is null and ee1 is null and ... and hh1 is null)
可以改成
where cc1 is not null or dd1 is not null or ee1 is not null or ... or hh1 is not null)

------解决方案--------------------
其中
where not (cc1 is null and dd1 is null and ee1 is null and ... and hh1 is null)
可以改成
where cc1 is not null or dd1 is not null or ee1 is not null or ... or hh1 is not null