并且时间在2015-3-1 11:00:00到2015-3-1 13:00:00之间的
代码:
WITH A AS(SELECT * FROM logtabl WHERE logid in(SELECT logid FROM logtable WHERE logtime BETWEEN '2015-3-1 11:00:00' AND '2015-3-1 13:00:00' GROUP BY Logid HAVING COUNT(*)=4) AND logtime BETWEEN '2015-3-1 11:00:00' AND '2015-3-1 13:00:00' ) SELECT * FROM A WHERE logid in(select logid FROM A GROUP BY A HAVING DATEDIFF(MINUTE,MIN(logtime),MAX(logtime))>40)
提示错误:在关键字 'with' 附近有语法错误
求论坛大神给以指导。
------解决思路----------------------
在with 前面加上分號; 試一下是否OK。
另查詢的時候怎麼可以group by A呢?
A不是字段。
------解决思路----------------------
;with a as (select logid,MIN(logtime) time_min,MAX(logtime) time_max from logtable
where logtime between '2015-3-1 11:00:00' AND '2015-3-1 13:00:00'
group by logid having COUNT(*)=4)
select logid from a where DATEDIFF(minute,time_min,time_max)>40