联表查询 列名无效
用到联表查询SQL语句时 最后运行输出总是报错 说s.Jprice列名无效 但这条语句在sqlserver中是可以执行的
到底是怎么回事呀 求解 谢谢各位大神
Jprice,Mprice是SPinfo表中的进价和卖价 xscout是XSjilu表中的销售数量 iid是两个表中的主外键关联
public void SelectSPpriceAll() throws SQLException {
float Jprice;
float Mprice;
int xscout;
float sum = 0;
Connection con = Database.getCon();
Statement sta = con.createStatement();
String sql = "select SUM((s.Mprice-s.Jprice)* x.xscout) from SPinfo s,XSjilu x where s.iid=x.iid";
ResultSet res = sta.executeQuery(sql);
while (res.next()) {
Jprice = res.getFloat("Jprice");
Mprice = res.getFloat("Mprice");
xscout = res.getInt("xscout");
sum += (Mprice - Jprice) * xscout;
System.out.println("所有商品的盈利总额为:" + sum + "元");
}
}