查询返回具有重复项的记录的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