对于每个唯一的列A,哪个SQL查询返回具有最新日期和时间的行(列B和C)? [英] What SQL query returns the row with the most recent Date and Time (Column B and C) for each unique Column A?
本文介绍了对于每个唯一的列A,哪个SQL查询返回具有最新日期和时间的行(列B和C)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于每个唯一的A列,哪种SQL查询返回具有最新日期和时间(B和C列)的行?
What SQL query returns the row with the most recent Date and Time (Column B and C) for each unique Column A?
推荐答案
如果C
实际上是设置了日期和时间信息的datetime
列,则可以执行以下操作:
If C
is actually a datetime
column with date and time information set, you can do:
select a, max(c)
from table
group by a;
如果B
是date
列,而C
是time
列,则您需要:
If B
is a date
column and C
is a time
column, then you need:
select a, max(convert(varchar(15), b) + ' ' + convert(varchar(15), c))
from table
group by a;
这篇关于对于每个唯一的列A,哪个SQL查询返回具有最新日期和时间的行(列B和C)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文