下午所有,我是一个stackoverflow处女,所以请放轻松。我很难从数据库中检索我需要的信息,并相信相关的子查询可能是答案,但我不确定。
我需要的所有信息都来自一张桌子:
╔══════╦══════════════╦══════════════╦════════════╦══════╦═════════════════════╦═════════════╗
║ COL1 ║ COL2 ║ FILENAME ║ COL4 ║ COL5 ║ DATETIME ║ COL7 ║
╠══════╬══════════════╬══════════════╬════════════╬══════╬═════════════════════╬═════════════╣
║ 2 ║ generaluser1 ║ shared2.txt ║ Shared ║ XP1 ║ 2013-04-04 19:23:09 ║ Checked In ║
║ 3 ║ generaluser1 ║ shared2.txt ║ Shared ║ XP1 ║ 2013-04-04 19:24:06 ║ Checked Out ║
║ 4 ║ generaluser1 ║ shared2.txt ║ Shared ║ XP1 ║ 2013-04-04 19:24:20 ║ Checked In ║
║ 5 ║ generaluser1 ║ restdoc3.txt ║ Restricted ║ XP1 ║ 2013-04-04 19:25:04 ║ Checked In ║
║ 6 ║ generaluser1 ║ restdoc3.txt ║ Restricted ║ XP1 ║ 2013-04-04 19:26:08 ║ Checked Out ║
║ 7 ║ generaluser1 ║ restdoc3.txt ║ Restricted ║ XP1 ║ 2013-04-04 19:26:21 ║ Checked In ║
║ 8 ║ generaluser1 ║ shared2.txt ║ Shared ║ XP1 ║ 2013-04-04 19:26:51 ║ Checked Out ║
║ 9 ║ generaluser1 ║ restdoc3.txt ║ Restricted ║ XP1 ║ 2013-04-04 19:28:41 ║ Checked Out ║
║ 10 ║ generaluser1 ║ restdoc3.txt ║ Restricted ║ XP1 ║ 2013-04-04 19:31:01 ║ Checked In ║
║ 11 ║ generaluser2 ║ restdoc3.txt ║ Restricted ║ XP2 ║ 2013-04-04 19:31:13 ║ Checked Out ║
║ 12 ║ generaluser1 ║ shared2.txt ║ Shared ║ XP1 ║ 2013-04-04 19:33:03 ║ Checked In ║
║ 13 ║ generaluser2 ║ restdoc3.txt ║ Restricted ║ XP2 ║ 2013-04-04 19:33:28 ║ Checked In ║
║ 14 ║ generaluser2 ║ restdoc4.txt ║ Restricted ║ XP2 ║ 2013-04-04 19:33:36 ║ Checked In ║
╚══════╩══════════════╩══════════════╩════════════╩══════╩═════════════════════╩═════════════╝
我要做的是为日期时间最新的每个文档名称(col2)检索一行。
因此,我想为上述行检索/输出的结果将只是:
╔══════╦══════════════╦══════════════╦════════════╦══════╦═════════════════════╦════════════╗
║ COL1 ║ COL2 ║ FILENAME ║ COL4 ║ COL5 ║ DATETIME ║ COL7 ║
╠══════╬══════════════╬══════════════╬════════════╬══════╬═════════════════════╬════════════╣
║ 12 ║ generaluser1 ║ shared2.txt ║ Shared ║ XP1 ║ 2013-04-04 19:33:03 ║ Checked In ║
║ 13 ║ generaluser2 ║ restdoc3.txt ║ Restricted ║ XP2 ║ 2013-04-04 19:33:28 ║ Checked In ║
║ 14 ║ generaluser2 ║ restdoc4.txt ║ Restricted ║ XP2 ║ 2013-04-04 19:33:36 ║ Checked In ║
╚══════╩══════════════╩══════════════╩════════════╩══════╩═════════════════════╩════════════╝
我可以设法获取我选择的文档或所有文档的最新行,但不能获取每个唯一文档的最新行。
提前感谢任何帮助我的人。