例如这样一段代码,非常感谢!
WITH CTE AS(
SELECT
*,
ROW_NUMBER() OVER(PARTITION BY MAC ORDER BY CreateTime DESC) CNT
FROM SystemInfo where CreateTime > (select left(convert(varchar,getdate(),21),7))
)
, CTE2 AS(
select MAC,min(createtime) as ct from systeminfo where CreateTime >(select left(convert(varchar,getdate(),21),7)) group by mac
)
,CTE4 AS(
select MAC,COUNT(MAC)as cnt from systeminfo where CreateTime > (select left(convert(varchar,getdate(),21),7)) group by mac
)
, cte3 AS(
SELECT A.ComputerName,a.hddinfo,a.hddfree,a.ram,a.cpu,A.MAC,A.CreateTime, b.ct AS [最早创建日期],d.cnt
FROM cte a join cte2 b ON a.MAC=b.MAC join cte4 d on a.mac=d.mac WHERE a.cnt=1
)
SELECT * FROM cte3
------解决方案--------------------
为什么要用(select left(convert(varchar,getdate(),21),7)))啊?
直接用left(convert(varchar,getdate(),21),7))不就行了吗?