对减号操作

时间:2016-07-05 15:13:45

标签: mysql sql mysql-workbench

SELECT flight_id, depart, arr, price 
FROM user.flightdb t2 LEFT JOIN
     user.booking t1
     ON t1.flightID = t2.flight_id
WHERE t2.source = 1 and t2.dest = 4 and
      t1.date = "02/02/2016" and t1.flightID IS NULL;

我想从flightdb(表格)中选择那些应该具有给定的来源和目的地的flight_id,以及在特定日期未出现在预订(表格)中的那些。

那么mysql中的查询是什么

2 个答案:

答案 0 :(得分:0)

您可以使用left join,但第二个表中的条件必须在on子句中。此外,您应该使用正确的日期格式:

SELECT flight_id, depart, arr, price 
FROM user.flightdb t2 LEFT JOIN
     user.booking t1
     ON t1.flightID = t2.flight_id and t1.date = '2016-02-02'
WHERE t2.source = 1 and t2.dest = 4 and t1.flightID IS NULL;

答案 1 :(得分:0)

您可以使用FOLLOWING QUERY

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

public class Template_StackOverflowExample extends JPanel{

    private JPanel diagPanel = new dialogTemplate();
    Object[] columnIdentifiers = {
        "id",
        "imei",
    };

    Object[][] data = {
        {"1", "123"},
        {"2", "123"},
        {"3", "123"}
    };

    private JDialog dialog;
    private static DefaultTableModel model;

    public Template_StackOverflowExample(){ 
        setLayout(new BorderLayout());
        JPanel pane = new JPanel(new BorderLayout());

        JButton addRow = new JButton("Add Row");
        addRow.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                openRowPane("Add Row");
            }
        });
        JButton editRow = new JButton("Edit Row");
        editRow.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                openRowPane("Edit Row");
            }
        });

        JPanel buttonPane = new JPanel(new GridLayout(0, 1));
        TitledBorder buttonBorder = new TitledBorder("Buttons");
        buttonPane.setBorder(buttonBorder);

        buttonPane.add(addRow);
        buttonPane.add(editRow);

        model = new DefaultTableModel();
        model.setColumnIdentifiers(columnIdentifiers);
        JTable table = new JTable(model);

        for(int i = 0; i < data.length; i++){
            model.insertRow(i, data[i]);
        }

        JScrollPane scrollPane = new JScrollPane(table);

        pane.add(buttonPane, BorderLayout.LINE_END);
        pane.add(scrollPane, BorderLayout.CENTER);

        add(pane, BorderLayout.CENTER);
    }

    public void openRowPane(String name){
        if(dialog == null){
            Window win = SwingUtilities.getWindowAncestor(this);
            if(win != null){
                dialog = new JDialog(win, name,    ModalityType.APPLICATION_MODAL);
                dialog.getContentPane().add(diagPanel);
                dialog.pack();
                dialog.setLocationRelativeTo(null);
            }
        }
        dialog.setVisible(true);
    }

    public static void createAndShowGUI(){
        JFrame frame = new JFrame("MCVE");      
        Template_StackOverflowExample mainPanel = new     Template_StackOverflowExample();
        frame.add(mainPanel);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);

        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args){
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

class dialogTemplate extends JPanel{

    private JComponent[] content;
    private String[] labelHeaders = {
        "ID:",
        "IMEI:",
    };

    public dialogTemplate(){
        JPanel diagTemplate = new JPanel();
        diagTemplate.setLayout(new BorderLayout());
        JPanel rowContent = new JPanel(new GridLayout(0, 2));

        JLabel idLabel = null;
        JLabel imeiLabel = null;

        JLabel[] labels = {
            idLabel,
            imeiLabel,
        };

        JTextField idTextField = new JTextField(20);
        JTextField imeiTextField = new JTextField(20);

        content = new JComponent[] {
            idTextField,
            imeiTextField,
        };

        for(int i = 0; i < labels.length; i++){
            labels[i] = new JLabel(labelHeaders[i]);
            rowContent.add(labels[i]);
            rowContent.add(content[i]);
            labels[i].setLabelFor(content[i]);
        }

        JButton save = new JButton("Save"); 
        save.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                closeWindow();
            }
        });
        JButton cancel = new JButton("Cancel");
        cancel.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                closeWindow();
            }
        });

        JPanel buttonPane = new JPanel(new GridLayout(0, 1, 5, 5));
        buttonPane.add(save);
        buttonPane.add(cancel);

        buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        diagTemplate.add(buttonPane, BorderLayout.PAGE_END);
        diagTemplate.add(rowContent, BorderLayout.CENTER);

        add(diagTemplate);
    }

    public void closeWindow(){
        Window win = SwingUtilities.getWindowAncestor(this);
        if(win != null) {
            win.dispose();
        }
    }
}