对你们许多人来说可能很简单。但我正在努力解决这个问题。 我有一个像这样的简单表。我想选择每个姓名有一条记录的记录,这些记录具有最近的日期。结果应如下所示。 名称日期 ---- ---- NAME1 2008-02 -12 06:32:14.380 NAME2 2004-03-14 06:35:03.420 NAME3 2002-07-20 06:23:21.463 NAME2 2001-03-01 04:33:24.356 NAME1 1999-03-14 02:35:04.410 NAME2 2005-01-10 06:55 :42.430 NAME2 2002-09-09 03:22:27.378 NAME3 2003-03-30 06:11:13.120 NAME3 2001 -04-10 06:03:45.454 结果 ------ NAME1 2008-02-12 06 :32:14.380 NAME2 2005-01-10 06:55:42.430 NAME3 2003-03-30 06:11:13.120 如何实现这一目标?
It may be simple for many of you. But I am stuggling with this. I have a simple table like this. I want to select the records with one record per each name which has recent date. the result should be like given below. NAME DATE ---- ---- NAME1 2008-02-12 06:32:14.380 NAME2 2004-03-14 06:35:03.420 NAME3 2002-07-20 06:23:21.463 NAME2 2001-03-01 04:33:24.356 NAME1 1999-03-14 02:35:04.410 NAME2 2005-01-10 06:55:42.430 NAME2 2002-09-09 03:22:27.378 NAME3 2003-03-30 06:11:13.120 NAME3 2001-04-10 06:03:45.454 RESULT ------ NAME1 2008-02-12 06:32:14.380 NAME2 2005-01-10 06:55:42.430 NAME3 2003-03-30 06:11:13.120 How can I achieve this?
推荐答案许多人可能很简单您。但我正在努力解决这个问题。 我有一个像这样的简单表。我想选择每个姓名有一条记录的记录,这些记录具有最近的日期。结果应如下所示。 名称日期 ---- ---- NAME1 2008-02 -12 06:32:14.380 NAME2 2004-03-14 06:35:03.420 NAME3 2002-07-20 06:23:21.463 NAME2 2001-03-01 04:33:24.356 NAME1 1999-03-14 02:35:04.410 NAME2 2005-01-10 06:55 :42.430 NAME2 2002-09-09 03:22:27.378 NAME3 2003-03-30 06:11:13.120 NAME3 2001 -04-10 06:03:45.454 结果 ------ NAME1 2008-02-12 06 :32:14.380 NAME2 2005-01-10 06:55:42.430 NAME3 2003-03-30 06:11:13.120 我怎样才能做到这一点? It may be simple for many of you. But I am stuggling with this. I have a simple table like this. I want to select the records with one record per each name which has recent date. the result should be like given below. NAME DATE ---- ---- NAME1 2008-02-12 06:32:14.380 NAME2 2004-03-14 06:35:03.420 NAME3 2002-07-20 06:23:21.463 NAME2 2001-03-01 04:33:24.356 NAME1 1999-03-14 02:35:04.410 NAME2 2005-01-10 06:55:42.430 NAME2 2002-09-09 03:22:27.378 NAME3 2003-03-30 06:11:13.120 NAME3 2001-04-10 06:03:45.454 RESULT ------ NAME1 2008-02-12 06:32:14.380 NAME2 2005-01-10 06:55:42.430 NAME3 2003-03-30 06:11:13.120 How can I achieve this?
展开 | 选择 | Wrap | 行号
你好 我的要求与原始查询,只有我的日期列格式如下: JAN08 MAR07 NOV06 AUG07 是否可以使用类似于您的解决方案的SQL,而不是使用日期表为每个月和年组合分配价值? 非常感谢! Hello I have the same requirements as the original query, only my date column format is as such: JAN08 MAR07 NOV06 AUG07 Is it possible to use an SQL similar to your solution rather than having a date table which assigns value to each of the month&year combinations? Thanks very much!
你好 我有与原始查询相同的要求,只有我的日期列格式如下: JAN08 MAR07 NOV06 AUG07 是否可以使用与您的解决方案类似的SQL,而不是使用可为其分配值的日期表每个月份和年份的组合? 非常感谢! Hello I have the same requirements as the original query, only my date column format is as such: JAN08 MAR07 NOV06 AUG07 Is it possible to use an SQL similar to your solution rather than having a date table which assigns value to each of the month&year combinations? Thanks very much!
尝试使用DATEPART函数来实现结果。
Try using DATEPART function to achieve your results.
更多推荐
选择具有条件的所有不同行。
发布评论