查询返回具有重复项的记录的1个实例 [英] Query to return 1 instance of a record with duplicates

查看:121
本文介绍了查询返回具有重复项的记录的1个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

INFO:我正在使用Microsoft SQL。

标题很混乱,下面是我使用的表格示例:

INFO: I am working with Microsoft SQL.
Ok the title is confusing but here is an example of the table I'm working with:

ID    Value    Signal    Read    Firmware    Date           Time
5     123      656       444       217       3/30/2009     11:00:00 AM
5     123      421       333       217       3/30/2009     04:00:00 PM
5     123      111       666       217       3/30/2009     05:00:00 PM
9     321      231       551       216       3/30/2009     09:00:00 AM
9     321      599       887       216       3/30/2009     09:30:00 AM

希望查询返回:

ID    Value    Signal    Read    Firmware    Date           Time
5     123      111       666       217       3/30/2009     05:00:00 PM
9     321      599       887       216       3/30/2009     09:30:00 AM

我试过:

SELECT DISTINCT ID, Value, Signal, Read, Firmware, Date, Time FROM ....

但这会返回所有结果。我也试过SELECT TOP 1 ...但我不能让它工作。我知道这很简单,但我很困惑如何让它只显示一个唯一的行。

感谢您的帮助。

But this returns all of the results. I have also tried SELECT TOP 1... but I couldn't get that to work. I know this is simple, but I'm confused on how to get this to display only 1 single unique row.
Thanks for the help.

推荐答案

您尝试过吗?

SELECT id, value, MIN(Signal), MIN(Read), MIN(Firmware), MIN(Date), MIN(Time)
FROM
  ...
GROUP BY
  ID, Value

这篇关于查询返回具有重复项的记录的1个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆