因此,我想从两个不同的表中计算每个卖家的销售总数。
而且我写下了代码,但是它不起作用.....谁能帮我吗???
因此,它应产生该SellerID = 1且count =13。SellerID = 2并且count = 14。所以我想为每个卖方产生3个销售总额,但是输出显示红线....

String[] sellerID = {"1","2","3"};
        int num = 0;
        String []totalAmountSale = new String[3];
 String sql = "SELECT tblOrder.SellerID, COUNT(*) " +
"FROM tblOrder, tblSeller " +
"WHERE tblOrder.SellerID = tblSeller.SellerID  " +
"GROUP BY tblOrder.SellerID"
                + "ORDER BY tblOrder.SellerID;";

        ResultSet rs = db.query(sql);
        try {
            while(rs.next())
            {
                totalAmountSale[num]= ""+rs.getInt(2);
                num++;

            }
            rs.close();
        } catch (SQLException ex) {
            Logger.getLogger(DatabaseWork.class.getName()).log(Level.SEVERE, null, ex);
        }
        String out = "";
        for (int i = 0; i < 3; i++) {
            out+= totalAmountSale[i]+"\n";
        }
        JOptionPane.showMessageDialog(null,out );
    }

最佳答案

您错过了一个空格:

 String sql = "SELECT tblOrder.SellerID, COUNT(*) " +
"FROM tblOrder, tblSeller " +
"WHERE tblOrder.SellerID = tblSeller.SellerID  " +
"GROUP BY tblOrder.SellerID "
                + "ORDER BY tblOrder.SellerID;";

07-27 22:44