join 没有一个表连接多个表用逗号分割的语法,你必须这么连接
select GY_JBBM.NAME,GY_KSDM.KSMC,GY_YGDM.YGMC,YS_JBZD.ZDSJ
from GY_YGDM join GY_JBBM on (GY_JBBM.id=GY_YGDM.id ) join GY_KSDM on(GY_YGDM.id = GY_KSDM.id) ………………
一个个把所有表都连接完
还有问题hi我。
INNER JOIN GY_JBBM,GY_KSDM,YS_JBZD
这3个表和 GY_YGDM是什么关系呢
---思路大概是
select GY_JBBM.NAME,GY_KSDM.KSMC,GY_YGDM.YGMC,YS_JBZD.ZDSJ
//into ll_newtable
from GY_YGDM INNER JOIN GY_JBBM
on GY_YGDM.ID= GY_JBBM.ID
INNER JOIN GY_KSDM
on GY_YGDM.ID= GY_KSDM.ID
.....
WHERE
YS_JBZD.ZDSJ between :ls_dtime1 and :ls_dtime2
from GY_YGDM INNER JOIN GY_JBBM,GY_KSDM,YS_JBZD
on YS_JBZD.ZDSJ between :ls_dtime1 and :ls_dtime2
错了.你的表间关系关联很混乱;你想要什么,GY_YGDM 和 GY_JBBM的内连接?
MSSQL SERVER2005及以上版本可换成如下:
;WITH
DD AS(
SELECT GY_JBBM.NAME,GY_YGDM.YGMC
FROM GY_YGDM A INNER JOIN GY_JBBM B
ON A表与B表的关联字段
)
SELECT DD.*,GY_KSDM.KSMC,YS_JBZD.ZDSJ
FROM DD,GY_KSDM,YS_JBZD