在来自另一个 table 的 table 中插入数据

Inserting a data in a table that comes from another table

我这里有这个查询:

rs = st.executeQuery("SELECT holderName,COUNT(holderName) as total, SUM(is_late) as total_late FROM (SELECT *,timestampdiff(minute, t1.startTime, t.IOTime) as is_late FROM (SELECT holderName, IODate, MIN(IOTime) as IOTime FROM tbl_records where IOStatus='Entry'AND IODate BETWEEN'"+from+"'AND'"+to+"' GROUP BY holderName, IODate) t JOIN tbl_emp t1 ON t.holderName = t1.name HAVING is_late > 0) AS t2 GROUP BY holderName  ORDER BY holderName, IODate");

这将 return 3 个值,我希望它把它放在另一个 table。

我试过这个:

st.executeUpdate("insert into tbl_temp values(null,name,total,total_late) SELECT holderName,COUNT(holderName) as total, SUM(is_late) as total_late FROM (SELECT *,timestampdiff(minute, t1.startTime, t.IOTime) as is_late FROM (SELECT holderName, IODate, MIN(IOTime) as IOTime FROM tbl_records where IOStatus='Entry'AND IODate BETWEEN'"+from+"'AND'"+to+"' GROUP BY holderName, IODate) t JOIN tbl_emp t1 ON t.holderName = t1.name HAVING is_late > 0) AS t2 GROUP BY holderName  ORDER BY holderName, IODate");

我在执行插入时遇到错误!

谢谢!

如果您输入了您遇到的错误,那就太好了。我现在能发现的一个错误是在你的查询语法中,你不能有 VALUES,它应该像 :

INSERT INTO tbl_temp(name,total,total_late)
SELECT holderName,COUNT(holderName) as tot...

看看here