我正在使用临时表
开发MySQL查询这是查询:
CREATE TEMPORARY TABLE t1 (
SELECT closedcash.HOSTSEQUENCE ,tickets.TICKETID ,
RECEIPTS.DATENEW,PAYMENTS.PAYMENT, PAYMENTS.NOTES, PAYMENTS.TOTAL
FROM PAYMENTS,RECEIPTS,closedcash,tickets
where CLOSEDCASH.MONEY = RECEIPTS.MONEY AND PAYMENTS.RECEIPT = RECEIPTS.ID
and closedcash.HOSTSEQUENCE=230 and receipts.ID=tickets.ID
ORDER BY RECEIPTS.DATENEW
);
CREATE TEMPORARY TABLE t2 (
select TICKETID, DATENEW, timestampdiff(SECOND,prevdatenew,DATENEW) as "diff"
from (
select TICKETID, DATENEW, @prevDateNew as prevdatenew,
@prevDateNew := DATENEW
from t1 order by DATENEW
) t1
);
UPDATE t2 SET diff =0 ORDER BY DATENEW ASC LIMIT 1;
SELECT
CONCAT(HOUR(t2.DATENEW), ':00-', HOUR(t2.DATENEW)+1, ':00') AS Hours ,
SEC_TO_TIME( sum(diff) / count(t2.DATENEW) )
from t2
group BY CONCAT(HOUR(t2.DATENEW), ':00-', HOUR(t2.DATENEW)+1, ':00')
order by t2.DATENEW ;
当我一个接一个地执行一个查询而不是一个文件时,它工作得很好, 但是当我将所有查询作为一个file.sql运行或者在sql编辑器中复制并粘贴phpmyadmin中的所有查询时,它显示null和零"奇怪的结果,我不知道为什么????
以下是我一次执行一个查询时的良好结果的屏幕截图:
http://orasql.org/2012/04/28/a-funny-fact-about-collect/
以下是我从一个文件执行所有查询时的错误结果的屏幕截图: