实施MIN或获得最低记录

发布于 2024-12-11 08:37:59 字数 898 浏览 0 评论 0原文

我想寻求有关如何解决此问题的帮助。我想添加 MIN 或某种查询,以仅显示下面 SQL 查询的 TotalTime 基础上的最低数字。

查询正在运行,但它显示重复的数据,我只想获得最低的 TotalTime。

提前致谢。

SELECT DISTINCT t1.name, 
  t1.Description, 
  t1.Issue, 
  t1.Dateres AS ATime, 
  t2.Dateres AS BAck, 
  TIMEDIFF(t2.Dateres,t1.Dateres) AS TotalTime, 
  t2.Acknowledge, t2.Resolution 
FROM t1
LEFT JOIN t2 ON t1.name = t2.name 
  AND t1.IPAddress = t2.IPAddress 
  AND t1.Description = t2.Description 
  AND t1.Issue = t2.Issue 
  AND t1.Severity = t2.Severity 
  AND t1.Timestamp = t2.Timestamp 
WHERE t1.Dateres IS NOT NULL
  AND t2.Dateres IS NOT NULL 
  AND t2.Acknowledge = '[email protected]' 
  AND t2.Dateres >= '2011-10-18 00:00:00' 
  AND t2.Dateres <= '2011-10-23 23:59:59' 
GROUP BY ATime
ORDER by BAck ASC;

I would like to ask for help on how to fix this. I would like to add a MIN or some sort of query to only show lowest number on the TotalTime base on the SQL query below.

The query is working but it show duplicate data and I only want to get the lowest TotalTime.

Thanks in advance.

SELECT DISTINCT t1.name, 
  t1.Description, 
  t1.Issue, 
  t1.Dateres AS ATime, 
  t2.Dateres AS BAck, 
  TIMEDIFF(t2.Dateres,t1.Dateres) AS TotalTime, 
  t2.Acknowledge, t2.Resolution 
FROM t1
LEFT JOIN t2 ON t1.name = t2.name 
  AND t1.IPAddress = t2.IPAddress 
  AND t1.Description = t2.Description 
  AND t1.Issue = t2.Issue 
  AND t1.Severity = t2.Severity 
  AND t1.Timestamp = t2.Timestamp 
WHERE t1.Dateres IS NOT NULL
  AND t2.Dateres IS NOT NULL 
  AND t2.Acknowledge = '[email protected]' 
  AND t2.Dateres >= '2011-10-18 00:00:00' 
  AND t2.Dateres <= '2011-10-23 23:59:59' 
GROUP BY ATime
ORDER by BAck ASC;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰葑 2024-12-18 08:37:59
SELECT 
t1.name, 
t1.Description, 
t1.Issue, 
t1.Dateres AS ATime, 
t2.Dateres AS BAck, 
Min(TIMEDIFF(t2.Dateres,t1.Dateres)) AS TotalTime, 
t2.Acknowledge, t2.Resolution 
FROM t1 LEFT JOIN t2 ON t1.name = t2.name 
AND t1.IPAddress = t2.IPAddress 
AND t1.Description = t2.Description 
AND t1.Issue = t2.Issue 
AND t1.Severity = t2.Severity 
AND t1.Timestamp = t2.Timestamp 
WHERE t1.Dateres is NOT NULL AND t2.Dateres is NOT NULL 
AND t2.Acknowledge = '[email protected]' 
AND t2.Dateres >= '2011-10-18 00:00:00' 
AND t2.Dateres <= '2011-10-23 23:59:59' 
GROUP BY t1.name ORDER by BAck ASC;
SELECT 
t1.name, 
t1.Description, 
t1.Issue, 
t1.Dateres AS ATime, 
t2.Dateres AS BAck, 
Min(TIMEDIFF(t2.Dateres,t1.Dateres)) AS TotalTime, 
t2.Acknowledge, t2.Resolution 
FROM t1 LEFT JOIN t2 ON t1.name = t2.name 
AND t1.IPAddress = t2.IPAddress 
AND t1.Description = t2.Description 
AND t1.Issue = t2.Issue 
AND t1.Severity = t2.Severity 
AND t1.Timestamp = t2.Timestamp 
WHERE t1.Dateres is NOT NULL AND t2.Dateres is NOT NULL 
AND t2.Acknowledge = '[email protected]' 
AND t2.Dateres >= '2011-10-18 00:00:00' 
AND t2.Dateres <= '2011-10-23 23:59:59' 
GROUP BY t1.name ORDER by BAck ASC;
⒈起吃苦の倖褔 2024-12-18 08:37:59

希望这会起作用:::

SELECT DISTINCT t1.name, 
t1.Description, 
t1.Issue, 
t1.Dateres AS ATime, 
t2.Dateres AS BAck, 
Min(TIMEDIFF(t2.Dateres,t1.Dateres)) AS TotalTime, 
t2.Acknowledge, t2.Resolution 
FROM t1 LEFT JOIN t2 ON t1.name = t2.name 
AND t1.IPAddress = t2.IPAddress 
AND t1.Description = t2.Description 
AND t1.Issue = t2.Issue 
AND t1.Severity = t2.Severity 
AND t1.Timestamp = t2.Timestamp 
WHERE t1.Dateres is NOT NULL AND t2.Dateres is NOT NULL 
AND t2.Acknowledge = '[email protected]' 
AND t2.Dateres >= '2011-10-18 00:00:00' 
AND t2.Dateres <= '2011-10-23 23:59:59' 
GROUP BY ATime ORDER by BAck ASC;

Hope this will work:::

SELECT DISTINCT t1.name, 
t1.Description, 
t1.Issue, 
t1.Dateres AS ATime, 
t2.Dateres AS BAck, 
Min(TIMEDIFF(t2.Dateres,t1.Dateres)) AS TotalTime, 
t2.Acknowledge, t2.Resolution 
FROM t1 LEFT JOIN t2 ON t1.name = t2.name 
AND t1.IPAddress = t2.IPAddress 
AND t1.Description = t2.Description 
AND t1.Issue = t2.Issue 
AND t1.Severity = t2.Severity 
AND t1.Timestamp = t2.Timestamp 
WHERE t1.Dateres is NOT NULL AND t2.Dateres is NOT NULL 
AND t2.Acknowledge = '[email protected]' 
AND t2.Dateres >= '2011-10-18 00:00:00' 
AND t2.Dateres <= '2011-10-23 23:59:59' 
GROUP BY ATime ORDER by BAck ASC;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文