-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を取得しています。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 に答える