2017-07-31 36 views
0

Difference between first entry and last entry for that day. Entries in that date can be 1 or more. If only one entry exists difference should be straight away 0
我試圖如何獲得日期時間差在兩個不同行的SQL

try{ 
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
     con=DriverManager.getConnection("jdbc:odbc:attendance"); 
     String sel="SELECT DATEDIFF(d, checkin, checkin)" 
       + " from checkinout where userid=1"; 
     stmt=con.createStatement(); 
     rs=stmt.executeQuery(sel); 
     while(rs.next()){ 
      System.out.println(rs.getString(1)); 
     } 
     System.out.println("Connected"); 
    }catch(Exception e){ 
     System.out.println(e); 
    } 

但出現異常 值java.sql.SQLException:[微軟] [ODBC Microsoft Access驅動程序]參數太少。預計2

謝謝

+0

嘗試先寫兩個查詢,一個只獲取第一個值,另一個獲取最後一個。一旦你有了,你可以結合你的主要查詢,這將發現不同之處。一次構建您的最終查詢。 – Mustafa

回答

0

檢查,如果你錯過了在DATEDIFF第一個參數報價()。

很可能d(表示日)應該用引號(類似於「d」,「d」或「\ d \」)。

用示例here檢查DATEDIFF的語法。

相關問題