我有一个表Visitors
,其中包含以下列
ID
,Visitors
,RegDate (date & time)
行:有4个,6个,8个,20个,11个,31个,43个访问者具有相同的日期(7月18日),但不是同一时间。
另一行:有1,5,10,1,13,15,18,11,23位游客的日期相同(7月19日),但不是同一时间。
像这样的东西
Id RegDate
4 2015-07-18 11:11:00.000
6 2015-07-18 11:11:01.000
8 2015-07-18 11:11:02.000
20 2015-07-18 11:11:03.000
11 2015-07-18 11:11:04.000
31 2015-07-18 11:11:05.000
43 2015-07-18 11:11:06.000
1 2015-07-19 11:11:00.000
10 2015-07-19 11:11:01.000
4 2015-07-19 11:11:02.000
13 2015-07-19 11:11:03.000
15 2015-07-19 11:11:04.000
18 2015-07-19 11:11:05.000
11 2015-07-19 11:11:06.000
23 2015-07-19 11:11:07.000
这是我的查询,显示最小值和最大值,包括日期。
SELECT MIN(Visitors), MAX(Visitors), cast(RegDate as date) AS DATE
FROM Visitor GROUP BY cast(RegDate as date)
ORDER BY DATE
我想删除“访问者”列中的所有行,但RegDate的“最小值”和“最大值”除外。
答案 0 :(得分:1)
答案 1 :(得分:0)
以下适用于您的数据。它使用您的GROUP BY
查询作为DELETE
DELETE V FROM
@Visitor AS v
JOIN
(
SELECT
RegDate,
MIN(Visitors) MinVisitors,
MAX(Visitors) MaxVisitors
FROM
@Visitor AS V
GROUP BY
RegDate
) T ON
v.RegDate = T.RegDate
AND V.Visitors <> T.MinVisitors
AND V.Visitors <> T.MaxVisitors