请考虑以下表格:
FileSpec:
id Name Extension
-------------------------------
1 Nima xlsx
2 Arian txt
3 Ava doc
4 Eli txt
下载日志:
Name UserName Date
---------------------------------------------------------
Nima User1 2019-03-14 12:01:43
Nima User2 2019-03-13 12:01:43
Ava User1 2018-08-11 15:32:00
Ava User2 2019-01-01 10:48:33
Ava User3 2019-03-01 02:02:02
Arian User1 2019-01-21 17:15:42
Arian User2 2019-02-21 09:18:10
我写了这个查询,它返回了我想要的结果:
select id, name, Ext, (select top 1 UserName from DownloadLog d where d.Name = f.Name order by [date] desc ), (select top 1 [date] from DownloadLog d where d.Name = f.Name order by [date] desc )
from FileSpec f
如您所见,我必须编写2个子查询才能返回UserName
和Date
字段。是否可以用join
编写上述查询,并且我可以直接从DownloadLog
表中最后下载用户?
谢谢
答案 0 :(得分:1)
您可以使用> tableresults[,4:11] / tableresults[,12]
Error in Ops.data.frame(tableresults[, 4:11], tableresults[, 12]) :
‘/’ only defined for equally-sized data frames
:
> dput(tableresults)
structure(list(ACTIVITY_X = c(40L, 60L, 62L, 60L, 66L, 60L, 57L,
54L, 52L, 93L, 80L, 14L, 61L, 51L, 40L, 20L, 21L, 5L, 53L, 48L,
73L, 73L, 21L, 29L, 63L, 59L, 57L, 51L, 53L, 67L, 72L, 74L, 70L,
60L, 74L, 85L, 77L, 68L, 58L, 80L, 34L, 45L, 34L, 60L, 75L, 62L,
66L, 51L, 53L, 48L, 62L, 62L, 57L, 5L, 1L, 12L, 23L, 5L, 4L,
0L, 13L, 45L, 44L, 31L, 68L, 88L, 43L, 70L, 18L, 83L, 71L, 67L,
75L, 74L, 49L, 90L, 44L, 64L, 57L, 22L, 29L, 52L, 37L, 32L, 120L,
45L, 22L, 54L, 30L, 9L, 27L, 14L, 3L, 29L, 12L, 61L, 60L, 29L,
15L, 7L, 6L, 0L, 2L, 0L, 4L, 1L, 7L, 0L, 0L, 0L, 0L, 0L, 1L,
23L, 49L, 46L, 8L, 31L, 45L, 60L, 37L, 61L, 52L, 51L, 38L, 86L,
60L, 41L, 43L, 40L, 42L, 42L, 48L, 64L, 71L, 59L, 0L, 27L, 12L,
3L, 0L, 0L, 8L, 21L, 6L, 2L, 7L, 4L, 3L, 3L, 46L, 46L, 59L, 53L,
37L, 44L, 39L, 49L, 37L, 47L, 17L, 36L, 32L, 33L, 26L, 12L, 8L,
31L, 35L, 27L, 27L, 24L, 17L, 35L, 39L, 28L, 54L, 5L, 0L, 0L,
0L, 0L, 17L, 22L, 25L, 12L, 0L, 5L, 41L, 51L, 66L, 39L, 32L,
53L, 43L, 40L, 44L, 45L, 48L, 51L, 41L, 45L, 39L, 46L, 59L, 31L,
5L, 24L, 18L, 5L, 15L, 13L, 0L, 26L, 0L), ACTIVITY_Y = c(47L,
74L, 63L, 56L, 61L, 53L, 40L, 41L, 49L, 32L, 54L, 13L, 99L, 130L,
38L, 14L, 6L, 5L, 94L, 96L, 38L, 43L, 29L, 47L, 66L, 47L, 38L,
31L, 36L, 35L, 38L, 72L, 54L, 44L, 45L, 51L, 80L, 48L, 39L, 85L,
42L, 39L, 37L, 75L, 36L, 45L, 32L, 35L, 41L, 26L, 99L, 163L,
124L, 0L, 0L, 24L, 37L, 0L, 6L, 0L, 29L, 29L, 26L, 27L, 54L,
147L, 82L, 98L, 12L, 83L, 97L, 104L, 128L, 81L, 42L, 102L, 60L,
79L, 58L, 15L, 14L, 75L, 75L, 40L, 130L, 40L, 13L, 54L, 42L,
7L, 10L, 3L, 0L, 15L, 8L, 75L, 55L, 26L, 18L, 1L, 13L, 0L, 0L,
0L, 1L, 0L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 17L, 45L, 38L, 10L, 31L,
52L, 36L, 65L, 97L, 45L, 59L, 49L, 92L, 51L, 34L, 21L, 20L, 29L,
28L, 22L, 32L, 30L, 86L, 0L, 15L, 7L, 4L, 0L, 0L, 0L, 11L, 3L,
0L, 1L, 3L, 1L, 0L, 72L, 62L, 98L, 55L, 26L, 39L, 28L, 81L, 20L,
52L, 12L, 48L, 24L, 40L, 30L, 5L, 6L, 40L, 37L, 33L, 26L, 17L,
14L, 39L, 27L, 28L, 67L, 0L, 0L, 0L, 0L, 0L, 10L, 12L, 14L, 7L,
0L, 2L, 39L, 67L, 74L, 28L, 23L, 57L, 34L, 36L, 36L, 37L, 46L,
43L, 73L, 65L, 31L, 64L, 128L, 17L, 3L, 12L, 17L, 0L, 9L, 7L,
0L, 17L, 0L), ACTIVITY_Z = c(62L, 95L, 88L, 82L, 90L, 80L, 70L,
68L, 71L, 98L, 97L, 19L, 116L, 140L, 55L, 24L, 22L, 7L, 108L,
107L, 82L, 85L, 36L, 55L, 91L, 75L, 69L, 60L, 64L, 76L, 81L,
103L, 88L, 74L, 87L, 99L, 111L, 83L, 70L, 117L, 54L, 60L, 50L,
96L, 83L, 77L, 73L, 62L, 67L, 55L, 117L, 174L, 136L, 5L, 1L,
27L, 44L, 5L, 7L, 0L, 32L, 54L, 51L, 41L, 87L, 171L, 93L, 120L,
22L, 117L, 120L, 124L, 148L, 110L, 65L, 136L, 74L, 102L, 81L,
27L, 32L, 91L, 84L, 51L, 177L, 60L, 26L, 76L, 52L, 11L, 29L,
14L, 3L, 33L, 14L, 97L, 81L, 39L, 23L, 7L, 14L, 0L, 2L, 0L, 4L,
1L, 8L, 0L, 0L, 0L, 0L, 0L, 1L, 29L, 67L, 60L, 13L, 44L, 69L,
70L, 75L, 115L, 69L, 78L, 62L, 126L, 79L, 53L, 48L, 45L, 51L,
50L, 53L, 72L, 77L, 104L, 0L, 31L, 14L, 5L, 0L, 0L, 8L, 24L,
7L, 2L, 7L, 5L, 3L, 3L, 85L, 77L, 114L, 76L, 45L, 59L, 48L, 95L,
42L, 70L, 21L, 60L, 40L, 52L, 40L, 13L, 10L, 51L, 51L, 43L, 37L,
29L, 22L, 52L, 47L, 40L, 86L, 5L, 0L, 0L, 0L, 0L, 20L, 25L, 29L,
14L, 0L, 5L, 57L, 84L, 99L, 48L, 39L, 78L, 55L, 54L, 57L, 58L,
66L, 67L, 84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, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 0L, 0L,
4L, 0L, 12L, 0L, 14L, 9L, 10L, 0L, 8L, 15L, 5L, 16L, 5L, 0L,
5L, 20L, 52L, 39L, 0L, 11L, 16L, 7L, 9L, 15L, 6L, 9L, 18L, 5L,
3L, 22L, 14L, 4L, 8L, 0L, 7L, 11L, 0L, 15L, 80L, 65L, 21L, 0L,
3L, 0L, 4L, 2L, 23L, 4L, 10L, 13L, 7L, 0L, 63L, 80L, 62L, 80L,
80L, 80L, 2L, 4L, 8L, 3L, 20L, 9L, 3L, 53L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 19L, 0L, 24L, 3L, 18L, 80L,
80L, 80L, 75L, 16L, 0L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 8L, 24L, 20L, 15L, 30L, 34L, 29L, 41L, 21L, 45L,
46L, 12L, 80L, 80L, 61L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 77L,
73L, 80L, 80L, 80L, 80L, 80L, 68L, 80L, 80L, 80L, 80L, 80L, 75L,
77L, 46L, 80L, 65L, 74L, 80L, 62L, 46L, 27L, 26L, 31L, 28L),
Grazing = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 22L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 61L, 75L,
5L, 0L, 62L, 61L, 64L, 28L, 15L,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, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L,
80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L, 80L), Event = c("Head-up",
"Grooming", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Vigilance", "Moving", "Moving", "Moving", "Moving", "Head-up",
"Head-up", "Head-up", "Head-up", "Moving", "Moving", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Grazing", "Grazing",
"Moving", "Moving", "Grazing", "Grazing", "Grazing", "Moving",
"Moving", "Grazing", "Grazing", "Grazing", "Grazing", "Grooming",
"Grooming", "Grazing", "Grazing", "Grooming", "Grooming",
"Grooming", "Vigilance", "Grazing", "Grazing", "Grazing",
"Grazing", "Vigilance", "Grazing", "Grazing", "Grazing",
"Grazing", "Moving", "Grazing", "Grazing", "Grazing", "Grazing",
"Grazing", "Moving", "Vigilance", "Vigilance", "Vigilance",
"Head-up", "Grazing", "Grazing", "Grazing", "Grazing", "Grazing",
"Grazing", "Grazing", "Grazing", "Grazing", "Grazing", "Grazing",
"Grazing", "Grazing", "Moving", "Head-up", "Vigilance", "Head-up",
"Head-up", "Head-up", "Grazing", "Grazing", "Grazing", "Grazing",
"Grazing", "Grooming", "Grazing", "Moving", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Moving", "Moving", "Vigilance",
"Vigilance", "Grazing", "Head-up", "Head-up", "Head-up",
"Moving", "Moving", "Grazing", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Grazing", "Grazing", "Grazing",
"Grazing", "Grazing", "Vigilance", "Grazing", "Grazing",
"Vigilance", "Vigilance", "Moving", "Moving", "Head-up",
"Head-up", "Moving", "Head-up", "Head-up", "Head-up", "Head-up",
"Head-up", "Head-up", "Head-up", "Grooming", "Grooming",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Vigilance",
"Head-up", "Head-up", "Head-up", "Head-up", "Head-up", "Grooming",
"Grooming", "Vigilance", "Head-up", "Vigilance", "Grooming",
"Head-up", "Vigilance", "Vigilance", "Vigilance", "Browsing",
"Moving", "Vigilance"), winning_cluster = c("cluster2", "cluster4",
"cluster4", "cluster4", "cluster4", "cluster4", "cluster4",
"cluster4", "cluster4", "cluster3", "cluster3", "cluster1",
"cluster3", "cluster3", "cluster2", "cluster1", "cluster1",
"cluster1", "cluster3", "cluster3", "cluster4", "cluster4",
"cluster2", "cluster2", "cluster4", "cluster4", "cluster4",
"cluster2", "cluster2", "cluster4", "cluster4", "cluster3",
"cluster4", "cluster4", "cluster4", "cluster3", "cluster3",
"cluster4", "cluster4", "cluster3", "cluster2", "cluster2",
"cluster2", "cluster4", "cluster4", "cluster4", "cluster4",
"cluster2", "cluster4", "cluster2", "cluster3", "cluster3",
"cluster3", "cluster1", "cluster1", "cluster1", "cluster2",
"cluster1", "cluster1", "cluster1", "cluster2", "cluster2",
"cluster2", "cluster2", "cluster4", "cluster3", "cluster4",
"cluster3", "cluster1", "cluster3", "cluster3", "cluster3",
"cluster3", "cluster3", "cluster2", "cluster3", "cluster4",
"cluster4", "cluster4", "cluster1", "cluster2", "cluster4",
"cluster4", "cluster2", "cluster3", "cluster2", "cluster1",
"cluster4", "cluster2", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster2", "cluster1", "cluster4", "cluster4",
"cluster2", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster2", "cluster2", "cluster2", "cluster1",
"cluster2", "cluster2", "cluster4", "cluster4", "cluster3",
"cluster4", "cluster4", "cluster2", "cluster3", "cluster4",
"cluster2", "cluster2", "cluster2", "cluster2", "cluster2",
"cluster2", "cluster4", "cluster4", "cluster4", "cluster1",
"cluster2", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster4", "cluster4",
"cluster3", "cluster4", "cluster2", "cluster2", "cluster2",
"cluster4", "cluster2", "cluster2", "cluster1", "cluster2",
"cluster2", "cluster2", "cluster2", "cluster1", "cluster1",
"cluster2", "cluster2", "cluster2", "cluster2", "cluster2",
"cluster1", "cluster2", "cluster2", "cluster2", "cluster4",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster2", "cluster4", "cluster3", "cluster2",
"cluster2", "cluster4", "cluster2", "cluster2", "cluster2",
"cluster2", "cluster2", "cluster4", "cluster4", "cluster4",
"cluster2", "cluster4", "cluster3", "cluster2", "cluster1",
"cluster1", "cluster1", "cluster1", "cluster1", "cluster1",
"cluster1", "cluster2", "cluster1")), row.names = c(NA, -215L
), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000000002541ef0>)```
答案 1 :(得分:1)
您可以将apply
与select f.id, f.name, f.Ext, d.username, d.[date]
from FileSpec f outer apply
(select top 1 d.*
from DownloadLog d
where d.Name = f.Name
order by [date] desc
) d
子句一起使用:
row_number()
返回两个或两个以上的行,这些行在有限的结果集中排在最后。
答案 2 :(得分:1)
您可以使用row_number()
select a.* from
(select f.*,d.date,d.UserName,
row_number() over(partition by f.name order by d.date desc) rn
from FileSpec f join DownloadLog d on f.Name=d.name
) a where a.rn=1