MS Access SQL Update表A,包含2个其他表的信息

时间:2015-06-08 09:57:34

标签: mysql ms-access

我有3张桌子:

CLIENTS
```````
num_sect
nbr
address
city

IMPORTED
````````
nbr
address
city
sector
part

SECTOR
``````
num_sect
city
sector
part

我应该对clients表进行扇区化,但只能使用与导入的地址匹配的扇区导入地址。

使用

Update table clients.num_sect内的

IMPORTED

num_sect from sector.

我使用此选项来匹配我应该更新内部客户端的所有行。

SELECT 
    c.num_sect, 
    c.nbr, 
    c.address, 
    c.num_abo, 
    imp.address, 
    imp.sector, 
    imp.part
FROM 
    clientes AS cli, imported as imp
WHERE 
    (c.address = imp.address and c.city = imp.city and c.nbr = imp.nbr)

但是,我无法通过客户之间的选择/关系更新num_sect

由于

解决方案:

UPDATE (SELECT ab.num_sect,ab.city,ab.nbr,ab.address,ab.num_abo,aps.address,aps.part& aps.sector AS CD,aps.nbr FROM clinets AS ab,导入AS aps WHERE( aps.address = ab.address和aps.city = ab.city和ab.nbr = aps.nbr))AS bla

INNER JOIN扇区bla.CD =(sector.part& secteur.sector& right(sector.sector,1))

SET ab.num_sect = sector.num_sect;

在比较和连接文本与cint(text = text& cint(text))时遇到问题似乎不认为连接文本和文本。 cint(nbr)是一个文本。 我改变了方法,但现在它可以工作,如果扇区只有一个数字(现在,它对我来说很好)。

1 个答案:

答案 0 :(得分:0)

我会这样试试:

UPDATE (SELECT ab.num_sect, ab.city, ab.nbr, ab.address, ab.num_abo, aps.address, 
               aps.part & aps.sector AS CD, aps.nbr 
        FROM clinets AS ab, imported AS aps 
WHERE (aps.address = ab.address 
       and aps.city = ab.city 
       and ab.nbr = aps.nbr)) AS bla
INNER JOIN sector ON bla.CD=(sector.part & secteur.sector & right(sector.sector,1)) 
SET ab.num_sect = sector.num_sect;