有两个表:
t1 t2
通过表t3建立关联
t3有spbh和spid字段t1里有2677条记录
select a.spcd,a.spbh,a.spmc,b.zhjj into t4
from t1 a,t2 b
where a.spbh in(select spbh from t3 where spid=b.spid)写入t4后为什么记录只有2524了啊?
t1 t2
通过表t3建立关联
t3有spbh和spid字段t1里有2677条记录
select a.spcd,a.spbh,a.spmc,b.zhjj into t4
from t1 a,t2 b
where a.spbh in(select spbh from t3 where spid=b.spid)写入t4后为什么记录只有2524了啊?
from t1 a,t2 b,t3 c
where a.spbh=c.spbh and c.spid=b.spid
HTTP://www.ebigear.com/Fund/PlayNews.php?NewsID=29453&ID=285885
from t1 a,t2 b
where a.spbh in(select spbh from t3 where spid=b.spid)
---------------------------------------------------------如果(select spbh from t3 where spid=b.spid)显示出的 spbh 数并非是所有T1中的spbh 话,结果当然会是如此
select a.spcd,a.spbh,a.spmc,b.zhjj into t4
from t1 a,(Select A1.spbh,B1.Zhjj From T2 B1,T3 A1 WHere A1.spid=B1.spid) B
WHere a.spbn=b.spbn如果结果还是一样的话,可以单独执行
Select A1.spbh,B1.Zhjj From T2 B1,T3 A1 WHere A1.spid=B1.spid
看下会有多少行记录
select a.spcd,a.spbh,a.spmc,b.zhjj into t4
from t1 a,t2 b
where a.spbh in(select spbh from t3 where spid=b.spid)要是以t1为标准,那样可以考虑使用LEFT OUTER 语句
SELECT a.spcd,a.spbh,a.spmc,b.zhjj INTO t4
FROM t1 AS a LEFT OUTER JOIN t2 AS b
ON a.spbh=b.spbh AND a.spid=b.spid
select a.spcd,a.spbh,a.spmc,b.zhjj into t4
from t1 a,t2 b,t3 c
where a.spbh=c.spbh and b.spid=c.spid
表t1是从excel导入的
excel中所有spbh都不为空
但导入SQL Server里有144个spbh为空
这是什么原因啊?