1

So I want to count the total number of sales for each seller from two different tables. And I wrote down the code but it does not work..... Can anyone please help me??? So it should produce that sellerID =1 and count = 13. sellerID=2 and count= 14. Something like this. So I want to produce 3 total amount of sales for each seller, but the output shows the red lines ....

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 );
    }
김규현
  • 11
  • 2

1 Answers1

0

You miss a space:

 String sql = "SELECT tblOrder.SellerID, COUNT(*) " +
"FROM tblOrder, tblSeller " +
"WHERE tblOrder.SellerID = tblSeller.SellerID  " +
"GROUP BY tblOrder.SellerID "
                + "ORDER BY tblOrder.SellerID;";
Gustav
  • 53,498
  • 7
  • 29
  • 55