同一表格同一字段每条记录差额的视图,老报错,求解
表名:sh_quotation
字段:ID(主键,标识), update_time(需要进行判断的列,格式:2007-06-06 9:00:00.000)
判断每条记录之间的update_time差
SELECT a.*, DATEDIFF(second, a.update_time, b.update_time) AS Expr1
FROM dbo.sh_quotation WITH (nolock) a INNER JOIN
dbo.sh_quotation WITH (nolock) b ON a.update_time > b.update_time
WHERE (b.update_time =
(SELECT MAX(c.update_time)
FROM sh_quotation c(nolock)
WHERE c.update_time < a.update_time))
老是报 第一行 a附近有错..实在找不出了..
------解决方案--------------------SELECT a.*, DATEDIFF(second, a.update_time, b.update_time) AS Expr1
FROM dbo.sh_quotation a WITH (nolock) INNER JOIN
dbo.sh_quotation b WITH (nolock) ON a.update_time > b.update_time
WHERE b.update_time =
(SELECT MAX(c.update_time)
FROM sh_quotation c(nolock)
WHERE c.update_time < a.update_time)