来自多个数据库的INNER JOIN上的未知字段

时间:2015-10-27 07:09:37

标签: mysql sql

我有以下sql语句:

INSERT INTO wk1_tbl (shohin_code, shohin_mei, variation_flag)                                                                                   
SELECT  ha.HINCD, ha.HINNMA, if (g.goods_para_id IS NULL, 0, 1) AS  variation                                                                                   
FROM ( SELECT KOSHINCD, count(HINCD) AS quatity                                                                                 
       FROM sc.HINMTF                                                                           
       GROUP BY KOSHINCD ) AS group_set                                                                         
       INNER JOIN  sc.HINMTA ha
        ON ha.HINCD = group_set.KOSHINCD                                                                                
       INNER JOIN master_hankoya.goods g 
        ON ha.WEBHINID = g.goods_id                                                                                 
WHERE ha.HINKB = '2' and ha.DATKB <> '9';   

我在多数据库上使用INNER JOIN,以便您可以看到scmaster_hankoya是差异数据库 当我运行它时,我收到错误:

Unknown column 'g.goods_id ' in 'on clause'

您可以看到表g的{​​{1}}别名,master_hankoya.goods是此列中的一列

我猜我的INNER JOIN有问题

请帮我纠正

更新:我再次检查并采取了一个愚蠢的问题,在查询中有一个特殊字符使其无法运行

3 个答案:

答案 0 :(得分:0)

不要使用master_hankoya.goods的别名,如

INSERT INTO wk1_tbl (shohin_code, shohin_mei, variation_flag)                                                                                   
SELECT  ha.HINCD, ha.HINNMA, if (master_hankoya.goods.goods_para_id IS NULL, 0, 1) AS  variation                                                                                   
FROM ( SELECT KOSHINCD, count(HINCD) AS quatity                                                                                 
   FROM sc.HINMTF                                                                           
   GROUP BY KOSHINCD ) AS group_set                                                                         
   INNER JOIN  sc.HINMTA ha
    ON ha.HINCD = group_set.KOSHINCD                                                                                
   INNER JOIN master_hankoya.goods  
    ON ha.WEBHINID = master_hankoya.goods.goods_id                                                                                 
WHERE ha.HINKB = '2' and ha.DATKB <> '9'; 

答案 1 :(得分:0)

试试这个

INSERT INTO wk1_tbl (shohin_code, shohin_mei, variation_flag)                                                                                   
SELECT  ha.HINCD, ha.HINNMA, if (g.goods_para_id IS NULL, 0, 1) AS  variation                                                                                   
FROM ( SELECT KOSHINCD, count(HINCD) AS quatity                                                                                 
       FROM sc.HINMTF                                                                           
       GROUP BY KOSHINCD ) AS group_set                                                                         
       INNER JOIN  sc.HINMTA ha
        ON ha.HINCD = group_set.KOSHINCD                                                                                
       INNER JOIN
        (select * from master_hankoya.goods ) g
        ON ha.WEBHINID = g.goods_id                                                                                 
WHERE ha.HINKB = '2' and ha.DATKB <> '9'; 

答案 2 :(得分:-1)

import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.LayerUI;
import javax.swing.plaf.basic.BasicComboBoxEditor;
//import javax.swing.plaf.metal.MetalComboBoxEditor;
import javax.swing.text.*;

public class ComboEditorJLayerTest {
  public JComponent makeUI() {
    JComboBox<String> comboBox = new JComboBox<>(new String[] {"aaaaaaa", "bbb"});
    comboBox.setEditable(true);
    comboBox.setEditor(new BasicComboBoxEditor() {
      private Component editorComponent;
      //@see javax/swing/plaf/synth/SynthComboBoxUI.java
      @Override public JTextField createEditorComponent() {
        JTextField f = new JTextField("", 9);
        f.setName("ComboBox.textField");
        return f;
      }
      @Override public Component getEditorComponent() {
        if (editorComponent == null) {
          JTextComponent tc = (JTextComponent) super.getEditorComponent();
          editorComponent = new JLayer<JTextComponent>(tc, new ValidationLayerUI());
        }
        return editorComponent;
      }
    });
    JPanel p = new JPanel();
    p.add(comboBox);
    return p;
  }
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      @Override public void run() {
        createAndShowGUI();
      }
    });
  }
  public static void createAndShowGUI() { 
    try {
      for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(laf.getName())) {
          UIManager.setLookAndFeel(laf.getClassName());
        }
      }
    }catch(Exception e) {
      e.printStackTrace();
    }
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(new ComboEditorJLayerTest().makeUI());
    f.setSize(320, 240);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
  }
}

//@see http://docs.oracle.com/javase/tutorial/uiswing/examples/misc/FieldValidatorProject/src/FieldValidator.java
class ValidationLayerUI extends LayerUI<JTextComponent> {
  @Override public void paint(Graphics g, JComponent c) {
    super.paint(g, c);
    JLayer jlayer = (JLayer) c;
    JTextComponent tc = (JTextComponent) jlayer.getView();
    if (tc.getText().length() > 6) {
      Graphics2D g2 = (Graphics2D) g.create();
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      int w = c.getWidth();
      int h = c.getHeight();
      int s = 8;
      int pad = 4;
      int x = w - pad - s;
      int y = (h - s) / 2;
      g2.setPaint(Color.RED);
      g2.fillRect(x, y, s + 1, s + 1);
      g2.setPaint(Color.WHITE);
      g2.drawLine(x, y, x + s, y + s);
      g2.drawLine(x, y + s, x + s, y);
      g2.dispose();
    }
  }
}

将此行更改为:

   INNER JOIN  sc.HINMTA ha

INNER JOIN master_hankoya.goods g

将该行更改为

INNER JOIN goods AS g

为表设置别名的语法是:

INNER JOIN  HINMTA AS ha