-1

在以下查询中,我想添加一个 where 语句以将结果缩小到具有 的结果m.extracard>0

SELECT u.id, u.onoma_u, u.name_u,
coalesce(u.programa, a.programa) as programa,
coalesce(u.barcode, a.barcode) as barcode,
coalesce(u.plan, a.plan) as plan,
coalesce(u.im_exp, a.im_exp) as im_exp,
coalesce(u.symb, a.symb) as symb
FROM (SELECT a1.id, a1.onoma_u, a1.name_u, a1.programa, 
             a1.barcode, a1.plan, a1.im_exp, a1.symb
      FROM aitisi a1 
      where a1.id between 6017 and 6063
      UNION
           SELECT a2.id, m.name, m.surname, NULL, NULL, NULL, NULL, NULL
           FROM members m 
           JOIN aitisi a2 ON a2.id = m.symbid 
           WHERE m.extracard > 0
       ) u
JOIN aitisi a ON a.id = u.id 
where a.id between 6017 and 6063

但在结果中,我得到的 ID 超出了 between 范围。有没有可能我把它放在WHERE m.extracard > 0了错误的地方?

4

1 回答 1

0
SELECT u.id, u.onoma_u, u.name_u,
coalesce(u.programa, a.programa) as programa,
coalesce(u.barcode, a.barcode) as barcode,
coalesce(u.plan, a.plan) as plan,
coalesce(u.im_exp, a.im_exp) as im_exp,
coalesce(u.symb, a.symb) as symb
FROM (SELECT a1.id, a1.onoma_u, a1.name_u, a1.programa, 
             a1.barcode, a1.plan, a1.im_exp, a1.symb
      FROM aitisi a1 
      JOIN mwmbers m ON a1.id = m.symbid 
           WHERE m.extracard > 0
      where a1.id between 6017 and 6063
      UNION
           SELECT a2.id, m.name, m.surname, NULL, NULL, NULL, NULL, NULL
           FROM members m 
           JOIN aitisi a2 ON a2.id = m.symbid 
           WHERE m.extracard > 0
       ) u
JOIN aitisi a ON a.id = u.id 
where a.id between 6017 and 6063
于 2012-06-29T16:57:36.993 回答