0

您好以下查询返回:没有为“t”的第 1 列指定列名。

  public ArrayList<DocumentModel> findByDate(String code, String date, String dateFinal) throws GeneralException{
    ArrayList<DocumentModel> docs = new ArrayList<DocumentModel>();
    String d1 = date;
    String delimiter = "-";
    String[]temp = d1.split(delimiter);
    String[]temp2 = dateFinal.split("-");
    String num="";
    String alfa="";
    if (code.compareTo("")!=0){
        String[] c1 = code.split(",");
        num = c1[0];
        alfa = c1[1];
    }

    try{
        String sql = "SELECT max(issuedate),airlineOid as airlineNumericCode FROM Document  WHERE ";

        if (alfa.compareTo("")!=0) sql+=" airlineOid='"+alfa+"' and ";

        sql+=" convert(varchar,issueDate,112) >= '" + temp[0]+ temp[1] +"00'  AND convert(varchar,issueDate,112) < '"+ temp2[0]+ temp2[1] +"32' group by airlineOid";

        String sql2="select d.*,'"+num+"' as airlineNumericCode from document d,("+sql+") as t where t.airlineOid=d.airlineOid and t.issueDate=d.issueDate ORDER BY issueDate DESC ";

        ResultSet rs = this.executeQuery(sql2);
        while(rs.next()){
            docs.add((DocumentModel)this.build(rs));
        }
        if(docs != null){
            return docs;
        } else {
            return docs = null;
        }
    } catch (SQLException ex){
        throw new GeneralException(ex);
    }
}

我看不到应该在哪里指定名称。非常感谢你!最好的问候伊格纳西奥

4

2 回答 2

2

您需要向 中添加列别名max(issuedate),如下所示:

String sql = "SELECT max(issuedate) as MaxIssueDate, airlineOid as airlineNumericCode FROM Document  WHERE ";  
于 2012-05-11T18:17:21.313 回答
0

我认为这是您的问题....您在 SQL 中将 airline0id 重命名为 airlineNumericCode。然后,在sql2 中,您尝试将其称为airline0id。试试这个:

String sql = "SELECT max(issuedate) as issueDate,airlineOid as airlineNumericCode FROM Document  WHERE ";

...

String sql2="select d.*,'"+num+"' as airlineNumericCode from document d,("+sql+") as t where t.airlineNumericCode=d.airlineOid and t.issueDate=d.issueDate ORDER BY issueDate DESC ";
于 2012-05-11T18:20:51.753 回答